如何使用python3中的模运算符计算疯子的数量?

2024-04-29 19:36:30 发布

您现在位置:Python中文网/ 问答频道 /正文

目前,我应该创建一个程序,“这个程序应该有变量的金额,图尼数,疯子数,25美分,10美分和5美分。假设用户总是输入一个最接近的镍币(没有硬币)。在程序的输出中清晰地显示所有的信息。“我想我可以使用模数运算符来计算硬币的剩余部分。你知道吗

目前,我已经尝试使用float函数输入程序的初始值和其他硬币的int值。你知道吗

print ("Hello and Welcome to the Make Change Machine")

Value =float(input("Please enter the amount in dollars and cents:"))
print ("In $",Value,"there are:")
loonie = int(Value/1)
toonie = int(Value/2)
quarters = int((Value-loonie)/0.25)
dimes = int(((Value-loonie)-quarters*0.25)/0.10)
nickel = int(((Value-loonie)- quarters*0.25 - dimes*0.10)/0.05) 
print ("Toonies:",toonie)
print("Loonie:",loonie)
print ("Quarters:",quarters)
print ("Dimes:",dimes)
print ("Nickels:",nickel)

我原以为输出是3,结果是7


Tags: andthe程序value硬币float金额int