214k views
2 votes
Write a program in Python to input Principle Amount, Rate, Time and a choice

from the user. If the choice inputted is 1, calculate the Simple Interest and print it.
If the choice inputted is 2, calculate the Compound Interest and print it.
Simple Interest = P*R*T/100
Compound Interest=P*(1+R/100)t

User Pfeilbr
by
5.6k points

1 Answer

2 votes

Answer:

P = float(input("Principal Amount: "))

R = float(input("Rate: "))

T = float(input("Time: "))

option = int(input("1 for Simple Interest, 2 for Compound interest: "))

if option == 1:

Interest = (P * R * T)/100

print("Interest: "+str(Interest))

elif option == 2:

Interest = P * (1 + R/100)**t

print("Interest: "+str(Interest))

else:

print("Invalid Selection")

Step-by-step explanation:

The next three line prompt user for Principal Amount, Rate and Time

P = float(input("Principal Amount: "))

R = float(input("Rate: "))

T = float(input("Time: "))

This line prompts user for option (1 for Simple Interest, 2 for Compound interest)

option = int(input("1 for Simple Interest, 2 for Compound interest: "))

If option is 1, simple interest is calculated

if option == 1:

Interest = (P * R * T)/100

print("Interest: "+str(Interest))

If option is 2, compound interest is calculated

elif option == 2:

Interest = P * (1 + R/100)**t

print("Interest: "+str(Interest))

If option is neither 1 nor 2, Invalid Selection is printed

else:

print("Invalid Selection")

User Neeraj Bhadani
by
5.7k points