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

Question:

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 countern")

hopefully someone/somebody can help me to solve this problem T_T

Asked By: Merong Shah

||

Answers:

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'
Answered By: Talha Tayyab

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])

Answered By: Merong Shah
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.