-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.py
More file actions
59 lines (43 loc) · 1.88 KB
/
14.py
File metadata and controls
59 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Program No. : 14
Program : Calculate Simple Interest & Compound Interest.
def calculate_interests():
"""
Calculates Simple Interest and Compound Interest based on user input.
"""
print("--- Interest Rate Calculator (SI & CI) ---")
# 1. Get user input
try:
principal = float(input("Enter the Principal Amount (P): "))
rate = float(input("Enter the Annual Interest Rate (R in %): "))
time = float(input("Enter the Time Period (T in years): "))
except ValueError:
print("Error: Please enter valid numerical values for all inputs.")
return
# Basic input validation
if principal < 0 or rate < 0 or time < 0:
print("Error: Principal, Rate, and Time cannot be negative.")
return
# --- Calculation 1: Simple Interest (SI) ---
# Formula: (P * R * T) / 100
simple_interest = (principal * rate * time) / 100
# Calculate the total amount for SI
si_total_amount = principal + simple_interest
# --- Calculation 2: Compound Interest (CI) ---
# Formula: P * (1 + R/100)^T - P
# Term 1: (1 + R/100)
rate_term = 1 + (rate / 100)
# Calculate the total amount for CI (A = P * (1 + R/100)^T)
ci_total_amount = principal * (rate_term ** time)
# Calculate the compound interest (CI = A - P)
compound_interest = ci_total_amount - principal
# 3. Display the results
print("\n--- Results ---")
print(f"P = {principal:.2f}, R = {rate:.2f}%, T = {time:.2f} years\n")
print("## 💵 Simple Interest (SI)")
print(f"Interest Earned (SI): **{simple_interest:.2f}**")
print(f"Total Amount (P + SI): {si_total_amount:.2f}")
print("\n## 📈 Compound Interest (CI) - Annually Compounded")
print(f"Interest Earned (CI): **{compound_interest:.2f}**")
print(f"Total Amount (A): {ci_total_amount:.2f}")
# Run the function
calculate_interests()