LearnFrenzy
Sign in Take a free test

Python Basics and Syntax · Python Basics Coding Problems · Question 2

Simple interest calculator in Python Solution, output & explanation

  • Program
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

Read the principal, the annual rate (%) and the number of years, each on its own line, and print the simple interest and the total amount, to two decimal places.

Solution
main.py Run
principal = float(input())
rate = float(input())
years = float(input())

interest = principal * rate * years / 100
amount = principal + interest

print(f"Simple interest: {interest:.2f}")
print(f"Total amount:    {amount:.2f}")

Output Verified by running it on Python 3

Simple interest: 6375.00
Total amount:    31375.00

SI = P × R × T / 100. float() accepts decimal input such as 8.5, and :.2f prints exactly two decimals.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links