this code i got from a website and still I am stock with the error in line elif in line 18. please help. and i am so fraustrated right now because this stockoverflow is not allowing me to post grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
#why does the elif statement says it's invalid. help please. thank you
reservation = {}
rnum = 0
while True:
mylist= []
choice = input('\nRESTAURANT RESERVATION SYSTEM\nSystem Menu\na. View all Reservationsn\nb. Make Reservation\nc. Delete Reservation\nd. Generate Report\ne. Exit\nEnter choice --> ').lower()
pass
if(choice == "a"):
if (len(reservation) == 0):
print("There are no reservations!!")
else:
print("#Date\t\t\tTime\t\tName\tAdults\tChildren")
for item in reservation:
list = reservation.get(item)
for i in list[:-1]:
print(f"{i}", end="\t\t")
print("\n")
elif(choice == "b"): #invalid syntax
try:
rnum = 1
name = input("Enter Name: ")
Date = input("Enter date(DD-MM-YYYY): ")
Time = input("Enter time(HH:MM): ")
adults = int(input("Number of adults: "))
Children = int(input("Number os children: "))
total = adults*500 Children*300
reservation[rnum]= [Date,Time,name,adults,Children,total]
print("hi")
except ValueError:
print("there is an incorrect value!! try again")
elif(choice == "c"):
getindex = 0;
rnumd = int(input("Enter Reservation number:"))
try:
reservation.pop(rnumd)
except KeyError:
print("Invalid reservation ID")
print("Reservation deleted")
elif(choice == "d"):
print("#Date\t\t\tTime\t\tName\tAdults\tChildren\tSubtotal")
for item in reservation:
for i in reservation.get(item):
print(f"{i}",end="\t")
print("\n")
elif(choice == "e"):
break
CodePudding user response:
Because you are stating elif after else. This is an illegal target
CodePudding user response:
#In your code else came before elif due this error occured
reservation = {}
rnum = 0
flag=1
while flag:
mylist= []
choice = input('\nRESTAURANT RESERVATION SYSTEM\nSystem Menu\na. View all Reservationsn\nb. Make Reservation\nc. Delete Reservation\nd. Generate Report\ne. Exit\nEnter choice --> ').lower()
pass
if(choice == "a"):
if (len(reservation) == 0):
print("There are no reservations!!")
else:
print("#Date\t\t\tTime\t\tName\tAdults\tChildren")
for item in reservation:
list = reservation.get(item)
for i in list[:-1]:
print(f"{i}", end="\t\t")
print("\n")
elif(choice == "b"): #invalid syntax
try:
rnum = 1
name = input("Enter Name: ")
Date = input("Enter date(DD-MM-YYYY): ")
Time = input("Enter time(HH:MM): ")
adults = int(input("Number of adults: "))
Children = int(input("Number os children: "))
total = adults*500 Children*300
reservation[rnum]= [Date,Time,name,adults,Children,total]
print("hi")
except ValueError:
print("there is an incorrect value!! try again")
elif(choice == "c"):
getindex = 0
rnumd = int(input("Enter Reservation number:"))
try:
reservation.pop(rnumd)
except KeyError:
print("Invalid reservation ID")
print("Reservation deleted")
elif(choice == "d"):
print("#Date\t\t\tTime\t\tName\tAdults\tChildren\tSubtotal")
for item in reservation:
for i in reservation.get(item):
print(f"{i}",end="\t")
print("\n")
elif(choice == "e"):
flag=0
else:
print("Invalid choice")