Thursday, 16 April 2026

πŸš€ Day 22/150 – Simple Interest in Python


πŸš€ Day 22/150 – Simple Interest in Python


Calculating Simple Interest (SI) is a fundamental concept in both mathematics and programming. It helps you understand how formulas translate into code and how Python can be used for real-world financial calculations.

The formula for Simple Interest is:

SI=P×R×T100\text{SI} = \frac{P \times R \times T}{100}

Where:

  • P = Principal amount
  • R = Rate of interest
  • T = Time (in years)

 

πŸ”Ή Method 1 – Direct Calculation

P = 1000 R = 5 T = 2 SI = (P * R * T) / 100 print("Simple Interest:", SI)




🧠 Explanation:

  • Values are directly assigned.
  • Formula is applied in one line.
  • Easy to understand and quick to execute.

πŸ‘‰ Best for: Learning basics and testing formulas.

πŸ”Ή Method 2 – Taking User Input

P = float(input("Enter principal: ")) R = float(input("Enter rate: ")) T = float(input("Enter time (years): ")) SI = (P * R * T) / 100 print("Simple Interest:", SI)




🧠 Explanation:

  • input() allows dynamic values.
  • float() ensures decimal calculations.
  • Makes the program interactive.

πŸ‘‰ Best for: Real-world scenarios.

πŸ”Ή Method 3 – Using a Function

def simple_interest(p, r, t): return (p * r * t) / 100 print(simple_interest(1000, 5, 2))



🧠 Explanation:

  • Function improves code reusability.
  • Parameters (p, r, t) make it flexible.
  • return gives the calculated value.

πŸ‘‰ Best for: Clean and reusable code.

πŸ”Ή Method 4 – Using Lambda Function

si = lambda p, r, t: (p * r * t) / 100 print(si(1000, 5, 2))




🧠 Explanation:
  • lambda creates a one-line function.
  • Useful for short calculations.

πŸ‘‰ Best for: Quick operations.

πŸ”Ή Method 5 – Using Tuple Input (Extended)

P = 1000 R = 5 T = 2 SI = (P * R * T) / 100 Amount = P + SI print("Simple Interest:", SI) print("Total Amount:", Amount)





🧠 Explanation:

  • Calculates both Simple Interest and Total Amount.
  • Amount = Principal + Interest
  • Useful in financial applications.

πŸ‘‰ Best for: Practical use cases.


⚡ Key Takeaways

  • Formula: (P × R × T) / 100
  • Use:
    • Direct values → for simplicity
    • Input → for user interaction
    • Functions → for modular code
    • Lambda → for short expressions
    • Extended logic → for real applications

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (245) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (29) Azure (10) BI (10) Books (262) Bootcamp (6) C (78) C# (12) C++ (83) Course (87) Coursera (300) Cybersecurity (30) data (5) Data Analysis (31) Data Analytics (22) data management (15) Data Science (344) Data Strucures (17) Deep Learning (152) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (4) flutter (1) FPL (17) Generative AI (70) Git (10) Google (51) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (42) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (285) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (14) PHP (20) Projects (32) pytho (1) Python (1306) Python Coding Challenge (1128) Python Mistakes (51) Python Quiz (473) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (49) Udemy (18) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)