Home > Enterprise >  how i can solve : can't multiply sequence by non-int of type 'float' (python)
how i can solve : can't multiply sequence by non-int of type 'float' (python)

Time:12-29

i'm just newbie for python , can anyone help me this code, im stuck for a week for this problem

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

CodePudding user response:

You are getting error because of this line:

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

You are multiplying string with float.

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

CodePudding user response:

thank you for you help, i found my answer here the correct code:

menu = "Espresso, Americano"

print (menu) order = input()

#changed the quantity variable to an integer so that it can be used in mathematical operations! quantity = int(input("How many " order " would you like?\n"))

#added a total variable and called the calculate_total function to calculate the total

price based on the quantity and price of the order.

def calculate_total(quantity, price): total = quantity * price return total

total = calculate_total(quantity, price[order])

  • Related