这个功能我缺少什么?

what am i missing for this function?

我试图在它说 "how many burgers do you want" 时获取输入,但是当我 运行 程序时我没有得到该选项。我在主要功能中缺少什么?当我 运行 程序时也没有弹出错误。

def main():
      endProgram = 'no'

      while endProgram == 'no': 
        totalFry = 0
        totalBurger = 0
        totalSoda = 0 
        endOrder = 'no'
        while endOrder == 'no':
          print ('Enter 1 for Yum Yum Burger')
          print ('Enter 2 for Grease Yum Fries')
          print ('Enter 3 for Soda Yum')
          option = input('Enter now -> ')
          if option == 1:
            totalBurger = getBurger(totalBurger)
          elif option == 2: 
            totalFry = getFries(totalFry)
          elif option == 3:
            totalSoda = getSoda(totalSoda)
          endOrder = input ('would you like to end your order? Enter No if you want to order more items: ')

        total = calcTotal(totalBurger, totalFry, totalSoda)
        printRecipt(total)

        endProgram= input ('do you want to end program? (enter no to process new order)')


    def getBurger(totalBurger):
      burgerCount = input ('enter number of burgers you want: ')
      totalBurger = totalBurgers + burgerCount * .99
      return totalBurgers

    def getFry(totalFry):
      fryCount = input ('Enter How Many Fries You want: ')
      totalFry = totalFries + fryCount * .79
      return totalFries

    def getSoda(totalSoda):
      sodaCount = input('enter number of sodas you would want: ')
      totalSoda = totalSoda + sodaCount * 1.09
      return totalSoda

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

    def printRecipt(total):
      print ('your total is $', total)

    main()

而不是:

if option == 1:

尝试:

if options == '1'

或者你可以这样做:

option = int(input('Enter now -> ')

输入 returns 字符串不是 int,因此不会触发 if 语句。

您在比较中混用了字符串和整数

例如在您的代码中:

 option = input('Enter now -> ')
 if option == 1:
     totalBurger = getBurger(totalBurger)

input( ) 返回的值总是一个字符串,所以当你比较 它是一个整数 (1) 结果是 always False

如果您想将用户输入用作整数,则需要将其转换为 第一个:

 option = input('Enter now -> ')
 option = int(option)
 if option == 1:
     totalBurger = getBurger(totalBurger)

您需要对其他 input() 调用进行类似的更改

option = input('Enter now -> ')将值作为字符串。

当您检查 option==1 时,您是在比较一个整数和一个字符串。这就是为什么 none 的条件通过并且您无法进行进一步输入的原因。

尝试替换 option = input('Enter now -> ') 使用 option = int(input('Enter now -> ')) 应该可以正常工作。