0

I know I'm being a bit daft, but I've been trying to get this simple bit of code ( part of a computing project ) to be rounded to the 2nd decimal place and so far i haven't been able to do so.

   loan = float(input("Please enter Amount that you would like to borrow (£):"))
loanduration = float(input("Please enter Duration of the loan(Months):"))


print("You will pay (£)" ,loan/loanduration, "per month")



It outputs like so  
Please enter Amount that you would like to borrow (£):4000
Please enter Duration of the loan(Months):12
You will pay (£) 333.3333333333333 per month
>>> 

1 Answers1

0
loan = float(input("Please enter Amount that you would like to borrow (£): "))
loanduration = float(input("Please enter Duration of the loan(Months): "))
print("You will pay (£) %.2f per month" % (loan/loanduration))

Example usage:

Please enter Amount that you would like to borrow (£):  4000
Please enter Duration of the loan(Months):  12
You will pay (£) 333.33 per month

Try it here!

Sash Sinha
  • 18,743
  • 3
  • 23
  • 40