我正在写一个脚本,要求用户提供不同面额的硬币数量,然后显示美元和美分的总额。在
我在这一点上被卡住了,我很困惑到底是什么错了。这是我的入门课的一部分,所以需要修改的细节非常感谢。我需要的输出是告诉用户有多少美元和剩余的美分。我现在对输出有问题。这个函数告诉我正确的答案,但当用词来回答时,分币是关的。
例如,当一便士是5;五分镍币是3;一角硬币是3;四分之三时,总数是1.25,但是函数显示“你有1美元和1美分”def main():
pennies = get_input("Enter pennies : ")
nickels = get_input("Enter nickels : ")
dimes = get_input("Enter dimes : ")
quarters = get_input("Enter quarters : ")
print("You entered : ")
print("\tPennies : " , pennies)
print("\tNickels : " , nickels)
print("\tDimes : " , dimes)
print("\tQuarters : " , quarters)
total_value = get_total(pennies, nickels, dimes, quarters)
dollars = get_dollars(pennies, nickels, dimes, quarters)
left_over_cents = get_left_over_cents(pennies, nickels, dimes, quarters)
print("Total = $",format(total_value, ".2f"), sep="")
print("You have", dollars, "dollars and", left_over_cents, "cent(s)")
def get_input(message):
get_input = int(input(message))
while get_input <= 0:
print("Error")
get_input = int(input(message))
return get_input
def get_total(pennies, nickels, dimes, quarters):
pennies = (.01 * pennies);
nickels = .05 * nickels;
dimes = .10 * dimes;
quarters = .25 * quarters;
total_value = pennies + nickels + dimes + quarters
return total_value
def get_dollars(pennies, nickels, dimes, quarters):
total_value = get_total(pennies, nickels, dimes, quarters)
dollars = format(total_value // 1, ".0f")
return dollars
def get_left_over_cents(pennies, nickels, dimes, quarters):
total_value = get_dollars(pennies, nickels, dimes, quarters)
left_over_cents = total_value
return left_over_cents
main()