可能的范围问题,将无法正确计算

2024-09-26 18:04:03 发布

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

在过去的三四个小时里,我一直在试着调试和研究这个问题,但还是搞不清楚。很可能很简单,因为我不知道该怎么做。这是我的密码:

def main():
    endProgram = "no"
    endOrder = "no"
    totalFry = 0.0
    totalSoda = 0.0
    total = 0.0
    tax = 0.0
    subtotal = 0.0
    option = 0
    burgerCount = 0
    fryCount = 0
    sodaCount = 0
    while(endProgram == "no"):
        resetVariables(totalBurger, totalFry, totalSoda, total, tax, subtotal)
        while(endOrder == "no"):
            option =int(input("Enter 1 for Yum Yum Burger\nEnter 2 for Grease Yum Fries\nEnter 3 for Soda Yum"))
            if(option == 1):
                getBurger(totalBurger, burgerCount)
            elif(option == 2):
                getFry(totalFry, fryCount)
            elif(option == 3):
                getSoda(totalSoda, sodaCount)
            endOrder = input("Do you want to end your order?")
        calcTotal(totalBurger, totalFry, totalSoda, total, subtotal, tax)
        printReceipt(total)
        endProgram = input("Do you want to end the program?")

def resetVariables(totalBurger, totalFry, totalSoda, total, tax, subtotal):
    totalBurger = 0
    totalFry = 0
    totalSoda = 0
    total = 0.0
    tax = 0.0
    subtotal = 0.0
    return(totalBurger, totalFry, totalSoda, total, tax, subtotal)

def getBurger(totalBurger, burgerCount):
    burgerCount = float(input("Enter the number of burgers you want.\n\t"))
    totalBurger = totalBurger + burgerCount * .99
    return(totalBurger, burgerCount)

def getFry(totalFry, fryCount):
    fryCount = float(input("Enter the number of fries you want.\n\t"))
    totalFry = totalFry + fryCount * .79
    return(totalFry, fryCount)

def getSoda(totalSoda, sodaCount):
    sodaCount = float(input("Enter the number of sodas you want.\n\t"))
    totalSoda = totalSoda + sodaCount * 1.09
    return(totalSoda, sodaCount)

def calcTotal(totalBurger, totalFry, totalSoda, total, subtotal, tax):
    subtotal = totalBurger + totalFry + totalSoda
    tax = subtotal * .6
    total = subtotal + tax
    return(totalBurger, totalFry, totalSoda, total, subtotal, tax)

def printReceipt(total):
    print("Your total is: $", total)
    return(total)

main()

我做的一切缩进正确,我只是累了,懒得编辑它。每当我运行这个,我输入的一切,它只是说我的总数是0.0美元,无论什么。这不是回溯的错误,所以我不能给出。谢谢你的帮助。如果您认为这篇文章以前已经有人回复过,请在您认为有帮助的地方发表文章


Tags: youinputreturndeftotaloptiontaxwant

热门问题