I am trying to make a menu calculator in which the user inputs items and the program will add up the order numbers and output the cost. I have done some of the code already but in the function in says can't assign to literal.
itemlist=["1","2","3","4","5","6","7","8","9"]
def itemcost():
1=3.50 #can't assign literal error is here
2=2.50
3=4.00
4=3.50
5=1.75
6=1.50
7=2.25
8=3.75
9=1.25
return itemcost
order=int(input("Enter order"))
while items in order:
itemcost+str(order)
On line 4 (and lines 5-12 after it) the
1
is read as the value one, i.e. a literal value. If you want to assign the value3.50
to a variable, you will need to name the variable something that cannot be interpreted as a number and does not begin with a number, such as_1
orvar1
.