为什么我的程序不会在python中添加我的更改?

时间:2014-11-05 03:39:29

标签: python

当我运行我的程序时,它会运行所有内容,但是当我想看到总输入时,我得到了 " total = $ none"而且我不知道为什么一直这么说?

def main():
    pennies = get_input1("Enter pennies : ")
    nickels = get_input2("Enter nickels : ")
    dimes = get_input3("Enter dimes : ")
    quarters = get_input4("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, cents = get_left_over_cents(pennies, nickels, dimes, quarters)
    left_over_cents = get_left_over_cents(pennies, nickels, dimes, quarters)
    print("Total = $", total_value, sep="")
    print('You have', dollars, "dollars and", cents, "cent(s)")

def get_input1(pennies):
    pennies = input("Enter Pennies: ")
    if int(pennies) < 0:
        print("Error: money cannot be negative")
        pennies = int(input("Enter correct amount of pennies: "))
    return pennies

def get_input2(nickels):
    nickels = input("Enter nickels: ")
    if int(nickels) < 0:
        print("Error: money cannot be negative")
        pennies = int(input("Enter correct amount of nickels: "))
    return nickels

def get_input3(dimes):
    dimes = input("Enter dimes: ")
    if int(dimes) < 0:
        print("Error: money cannot be negative")
        pennies = int(input("Enter correct amount of dimes: "))
    return dimes

def get_input4(quarters):
    quarters = input("Enter quarters: ")
    if int(quarters) < 0:
        print("Error: money cannot be negative")
        pennies = int(input("Enter correct amount of quarters: "))
    return quarters

def get_total(pennies, nickels, dimes, quarters):
    amount_pennies = (int(pennies) * .01)
    amount_nickels = (int(nickels) * .05)
    amount_dimes = (int(dimes) * .10)
    amount_quarters = (int(quarters) * .25)

def get_left_over_cents(pennies, nickels, dimes, quarters):
    total = int(pennies) + 5*int(nickels) + 10*int(dimes) + 25*int(quarters)
    return total // 100, total % 100

main()

1 个答案:

答案 0 :(得分:1)

您没有从get_total函数返回任何内容。

def get_total(pennies, nickels, dimes, quarters):
    amount_pennies = (int(pennies) * .01)
    amount_nickels = (int(nickels) * .05)
    amount_dimes = (int(dimes) * .10)
    amount_quarters = (int(quarters) * .25)
    return amount_pennies + amount_nickels + amount_dimes + amount_quarters

在Python中,如果函数没有显式return任何值,则默认返回None