亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這個功能我錯過了什么?

這個功能我錯過了什么?

米脂 2022-08-11 17:48:10
我試圖獲取“你想要多少漢堡”的輸入,但是當我運行程序時,我沒有得到這個選項。我在主函數中缺少什么?當我運行程序時也沒有彈出任何錯誤。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()
查看完整描述

3 回答

?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

而不是:

if option == 1:

嘗試:

if options == '1'

或者你可以做:

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

輸入返回的字符串不是 int,因此不會觸發 if 語句。


查看完整回答
反對 回復 2022-08-11
?
茅侃侃

TA貢獻1842條經驗 獲得超22個贊

您在比較中混合了字符串和 int


例如,在代碼中:


 option = input('Enter now -> ')

 if option == 1:

     totalBurger = getBurger(totalBurger)

input( ) 返回的值始終是一個字符串,因此當您將其與整數 (1) 進行比較時,結果始終為 False


如果要將用戶輸入用作整數,則需要先將其轉換為一個:


 option = input('Enter now -> ')

 option = int(option)

 if option == 1:

     totalBurger = getBurger(totalBurger)

您需要對其他輸入()調用進行類似的更改


查看完整回答
反對 回復 2022-08-11
?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

該行將值作為字符串。option = input('Enter now -> ')

當您進行檢查時,您正在將整數與字符串進行比較。這就是為什么沒有一個條件通過并且您無法接受進一步輸入的原因。option==1

嘗試替換為,它應該工作正常。option = input('Enter now -> ')option = int(input('Enter now -> '))


查看完整回答
反對 回復 2022-08-11
  • 3 回答
  • 0 關注
  • 108 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號