2017-02-20 192 views
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 (£)" ,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 
>>> 

回答

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)) 

用法示例:

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 

試試吧here!

+1

謝謝你幫我這個,因爲它是一個深夜,我完全忘了這一點 –