Operators · Python example
Use arithmetic operators and formatted floats to compute interest.
Simple interest is calculated with a short formula. This example also shows how to round floating-point output to two decimal places.
principal = 1500
rate = 7.5
years = 3
interest = (principal * rate * years) / 100
total = principal + interest
print(f"Simple interest: {interest:.2f}")
print(f"Total amount: {total:.2f}")