I am currently writing a ferry ticket reservation program that has a function to view the seatings (I'm using a list). The code below is going to be a function in my program. When running the code, when I input 1 it prints my list but if I input any other value it asks for another input.
For example if I input 2, the program asks for another input and if I input the same value (2) it will print what I want. But if I input a different value such as 3 when it asks the second time, it will ask for a third input. If my third input is the same as my second input, it will print what I want BUT if I input a different value, it will start to print and reach an error.
I have all 3 ferry seatings in one list so I wrote ferry1, ferry2, etc. just for testing purposes.
Bellow is my whole code. Sorry for the poor formatting of this post as it is my first complex program as well as my first time using a forum. Why is this happening and how can I solve this problem? Thanks in advance!
seatings = [ ["ferry1", "B2", "B3", "B4", "B5"],
["B6", "B7", "B8", "B9", "B10"],
["E1", "E2", "E3", "E4", "E5"],
["E6", "E7", "E8", "E9", "E10"],
["E11", "E12", "E13", "E14", "E15"],
["E16", "E17", "E18", "E19", "E20"],
["E21", "E22", "E23", "E24", "E25"],
["E26", "E27", "E28", "E29", "E30"],
["E31", "E32", "E33", "E34", "E35"],
["E36", "E37", "E38", "E39", "E40"],
["ferry2", "B2", "B3", "B4", "B5"],
["B6", "B7", "B8", "B9", "B10"],
["E1", "E2", "E3", "E4", "E5"],
["E6", "E7", "E8", "E9", "E10"],
["E11", "E12", "E13", "E14", "E15"],
["E16", "E17", "E18", "E19", "E20"],
["E21", "E22", "E23", "E24", "E25"],
["E26", "E27", "E28", "E29", "E30"],
["E31", "E32", "E33", "E34", "E35"],
["E36", "E37", "E38", "E39", "E40"],
["ferry3", "B2", "B3", "B4", "B5"],
["B6", "B7", "B8", "B9", "B10"],
["E1", "E2", "E3", "E4", "E5"],
["E6", "E7", "E8", "E9", "E10"],
["E11", "E12", "E13", "E14", "E15"],
["E16", "E17", "E18", "E19", "E20"],
["E21", "E22", "E23", "E24", "E25"],
["E26", "E27", "E28", "E29", "E30"],
["E31", "E32", "E33", "E34", "E35"],
["E36", "E37", "E38", "E39", "E40"] ]
import datetime
today = datetime.date.today()
def getchoice():
ch=int(input("Please enter ferryID: "))
return ch
if (getchoice()== 1):
ID=1
a=0
b=2
c=10
elif (getchoice()==2):
ID=2
a=10
b=12
c=20
elif (getchoice()==3):
ID=3
a=20
b=22
c=30
print("-"*35)
print("Ferry ID:", ID, " ", "Date:",today)
print("-"*35)
print("Business Class")
for item in ferry[a:b] :
print( "-"*33, "\n",
item[0], " "*( 3-len( item[0] ) ),
":", item[1], " "*( 3-len( item[1] ) ),
":", item[2], " "*( 3-len( item[2] ) ),
":", item[3], " "*( 3-len( item[3] ) ),
":", item[4], " "*( 3-len( item[4] ) ))
print("-"*33)
print("Economy Class")
for item in ferry[b:c]:
print( "-"*33, "\n",
item[0], " "*( 3-len( item[0] ) ),
":", item[1], " "*( 3-len( item[1] ) ),
":", item[2], " "*( 3-len( item[2] ) ),
":", item[3], " "*( 3-len( item[3] ) ),
":", item[4], " "*( 3-len( item[4] ) ))
print("-"*33)