我知道我有点愚蠢,但是我一直试图让这个简单的代码(计算项目的一部分)四舍五入到小数点后两位,到目前为止我还没有&已经能够这样做了。
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 :(得分: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!