简体   繁体   English

我如何解决:不能将序列乘以“float”类型的非整数(python)

[英]how i can solve : can't multiply sequence by non-int of type 'float' (python)

i'm just newbie for python, can anyone help me this code, im stuck for a week for this problem我只是 python 的新手,任何人都可以帮我这个代码,我为这个问题困了一个星期

here my code:这是我的代码:

price = {
    "Espresso": 5.80,
    "Americano": 6.90,
}

currency = "$"

print ("welcome coffee machine!\t")
name = input ("can i get your name?\n")

print ("what do you like to order mr/ms " + name + "\n"  )


menu = ("Espresso, Americano")

print (menu)
menu = (input())


quantity = input("How many " + menu + " would you like?\n")
quantity = str(input())

#im stuck at here! T_T 
if menu == "Espresso" :
    price = 5.80
    total = quantity * price
    quantity.append(quantity)
    price.append(price)
    print(total)

elif menu == "Americano":
    price = 6.90
    total = quantity * price
    quantity.append(quantity)
    price.append(price)
    print(total)

else:
     menu()

#invoice receipt

print("Thank you for order " + name + ", please wait your " + menu + " at counter\n")

hopefully someone/somebody can help me to solve this problem T_T希望有人能帮我解决这个问题T_T

You are getting error because of this line:由于这一行,您收到错误消息:

quantity = str(input())
price = 5.80
total = quantity * price

You are multiplying string with float .您正在将stringfloat相乘。

TypeError: can't multiply sequence by non-int of type 'float'

thank you for you help, i found my answer here the correct code:谢谢你的帮助,我在这里找到了正确的答案代码:

menu = "Espresso, Americano" menu = "浓缩咖啡,美式咖啡"

print (menu) order = input()打印(菜单)顺序=输入()

#changed the quantity variable to an integer so that it can be used in mathematical operations? #将数量变量更改为 integer 以便它可以用于数学运算? quantity = int(input("How many " + order + " would you like?\n")) quantity = int(input("你要多少" + order + "?\n"))

#added a total variable and called the calculate_total function to calculate the total #添加一个total变量调用calculate_total function来计算总和

price based on the quantity and price of the order.价格根据订单的数量和价格。

def calculate_total(quantity, price): total = quantity * price return total def calculate_total(quantity, price): total = quantity * price 返回总计

total = calculate_total(quantity, price[order]) total = calculate_total(数量, 价格[订单])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决python中的“无法将序列乘以'float'类型的非整数”的问题 - How do I solve the issue “can't multiply sequence by non-int of type 'float'” in python 不能在Python中将序列乘以'float'类型的非int - Can't multiply sequence by non-int of type 'float' in Python Python不能将序列乘以'float'类型的非int - Python can't multiply sequence by non-int of type 'float' 不能通过Non-Int类型浮点乘以序列? 蟒蛇 - Can't Multiply Sequence By Non-Int of Type Float? Python 不能将序列乘以'float'Python类型的非整数 - can't multiply sequence by non-int of type 'float' Python 如何解决TypeError:无法将序列乘以'float'类型的非整数 - How to solve TypeError: can't multiply sequence by non-int of type 'float' 为什么我得到错误不能将序列乘以'float'PYTHON类型的非int - Why do I get error can't multiply sequence by non-int of type 'float' PYTHON 如何修复“类型错误:不能将序列乘以非整数类型的‘浮点数’? - How do I fix 'Type Error: can't multiply sequence by non-int of type 'float'? TypeError:无法将序列乘以float类型的非整数 - TypeError:can't multiply sequence by non-int of type float 错误是:无法将序列乘以'float'类型的非整数 - The error was:can't multiply sequence by non-int of type 'float'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM