を働いていない:のpythonでの私の乗算は、私は以下のコードに取り組んforループ内の乗算を取得しようとしている
#products list and it's values per unity
tomato = 2
potato = 3
carrot = 1
pricePaid = int()
print("Welcome to my grocery shop!\n")
productList = ["Potato", "Tomato", "Carrot"]
print("What will you want today?\n""We have:")
print(*productList, sep=', ')
product = input("What will it be? ")
quantity = int(input("And how many do you want? "))
for productChoice in product:
if productChoice == "Potato":
pricePaid = quantity * potato
elif productChoice == "Tomato":
pricePaid = quantity * tomato
elif productChoice == "Carrot":
pricePaid = quantity * carrot
print("Here's your bag with {0} {1}s. The total is ${2:.2f}.".format(quantity, product, pricePaid))
が、私はそれは量であるべきところ私の結果として$ 0.00取得しています* productPrice:
"Here's your bag with 1 Tomatos. The total is $0.00."
なぜ失敗しますか?私はここで何が欠けていますか?
私は
事前のおかげでPythonの3.xを使用しています!
私は '製品のために選択してください:'とは思っていません。 'product'は文字列(' input'は文字列を返します)であるため、 'productChoice'はあなたの入力のすべての文字になります。 –