第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

價(jià)格不相加

價(jià)格不相加

qq_遁去的一_1 2023-09-12 17:45:50
為 IT 課程創(chuàng)建一個(gè)披薩訂購(gòu)程序,幾乎完成了,但我目前遇到了一個(gè)我似乎無(wú)法解決或不知道如何解決的問(wèn)題。當(dāng)用戶(hù)選擇完披薩后,應(yīng)該將他們選擇的披薩的總成本加起來(lái),但問(wèn)題是他們沒(méi)有加起來(lái),而是價(jià)格保持不變 Name:JackTelephone:47347842ORDER:['2. Hawaiian pizza', 8.5]['1. Pepperoni pizza', 8.5]['3. Garlic cheese pizza (with choice of sauce)', 8.5]Total Price: 8.50這是他們必須選擇的價(jià)目表['1. Pepperoni pizza', 8.5]['2. Hawaiian pizza', 8.5]['3. Garlic cheese pizza (with choice of sauce)', 8.5]['4. Cheese pizza (with choice of sauce)', 8.5]['5. Ham and cheese pizza', 8.5]['6. Beef & onion pizza', 8.5]['7. Vegetarian pizza', 8.5]['8. BBQ chicken & bacon aioli pizza', 13.5]['9. Boneless pizza (italian style anchovy with no bones)', 13.5]['10. Pizza margherita', 13.5]['11. Meat-lover’s pizza', 13.5]['12. Tandoori pizza', 13.5]我不知道問(wèn)題是否出在這段代碼中,但看起來(lái)確實(shí)如此。我最初嘗試使用“cost.append”,但它只出現(xiàn)了這樣的錯(cuò)誤+ 不支持的操作數(shù)類(lèi)型:“int”和“str”def Choice_of_pizza():    for i in range(1,pizza_no                   +1): #Repeats a number of times (number user has inputted)      while True:        try: #Validating inputs          pizza_kind = int(input("Choice of pizza(s):"))          if pizza_kind < 1:            print("Refer to PIZZA MENU for number order")            continue          if pizza_kind > 12:            print("Refer to PIZZA MENU for number order")            continue          else:            pizza = pizza_kind - 1 #Makes the list start at 1            cost.append(MENU[pizza_kind-1][0][pizza])            customerOrder.append(MENU[pizza_kind-1][pizza])            因此,我將其替換為“cost=+customerOrder[i][1]”,但即便如此,它在某種程度上也適用于添加的披薩名稱(chēng),但不適用于客戶(hù)詳細(xì)信息的價(jià)格。預(yù)期的目標(biāo)是,當(dāng)用戶(hù)一一輸入選項(xiàng)時(shí),它會(huì)取出名稱(chēng)并將價(jià)格放入成本列表中,但似乎并沒(méi)有這樣做。
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

代碼問(wèn)題:

  1. 對(duì)于加法賦值,語(yǔ)法為:

    x += y # 將 x 分配給 (x + y)

不是:

x?=?+y??#?this?assign?x?to?y
  1. Glbol 不會(huì)在您的代碼中造成問(wèn)題,但通常會(huì)令人不悅并對(duì)編程技能產(chǎn)生負(fù)面影響,即為什么全局變量是邪惡的?。

Choice_of_pizza功能修復(fù)

def Choice_of_pizza():

? ? for i in range(1,pizza_no +1): #Repeats a number of times (number user has inputted)

? ? ?

? ? ? while True:

? ? ? ? try: #Validating inputs

? ? ? ? ? pizza_kind = int(input("Choice of pizza(s):"))

? ? ? ? ? if pizza_kind < 1:

? ? ? ? ? ? print("Refer to PIZZA MENU for number order")

? ? ? ? ? ? continue

? ? ? ? ? if pizza_kind > 12:

? ? ? ? ? ? print("Refer to PIZZA MENU for number order")

? ? ? ? ? ? continue

? ? ? ? ? else:

? ? ? ? ? ? pizza = pizza_kind - 1 #Makes the list start at 1

? ? ? ? ? ? print('\nYou have chosen {}\n'.format(MENU[pizza_kind-1][0]))

? ? ? ? ? ? customerOrder.append(MENU[pizza_kind-1])

? ? ? ? ? ? cost = 0

? ? ? ? ? ? for i in range(len(customerOrder)):

? ? ? ? ? ? ? cost += customerOrder[i][1]

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? global total_cost? # globals are discouraged

? ? ? ? ? ? total_cost=0

? ? ? ? ? ? #Sum of the pizzas

? ? ? ? ? ? global Combined_Total # globals are discouraged

? ? ? ? ? ? if delivery == "D": #Adds $3 dollars to the total cost if delivery

? ? ? ? ? ? ? total_cost += cost

? ? ? ? ? ? ? Combined_Total = total_cost + Delivery_cost

? ? ? ? ? ? else: #Price stays the same if pick up

? ? ? ? ? ? ? total_cost += cost

? ? ? ? ? ? ? Combined_Total = total_cost

? ? ? ? ? ? break

? ? ? ? except ValueError:#Validating inputs - accepts only numbers and can't be left blank?

? ? ? ? ? print("Please use numbers only")

? ? ? ? ? continue


查看完整回答
反對(duì) 回復(fù) 2023-09-12
  • 1 回答
  • 0 關(guān)注
  • 113 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)