I have this function, which is part of a larger code I am working on for a class, so I am not looking for all the answers, just a little help with this part because I really don't know how to proceed. I have a function that asks for multiple inputs. firstname, lastname, bus row, and bus seat. these are then split and printed into a text file that I will do some other things with that i have not included the code for because I am still working on it. the first two entries need to be strings(first and last name), and the second two need to be numbers ( at least for now) the first number needs to be 1-4(row), and the second needs to be 1-15(seat), because that is all the seats available. I want an error to come back if anything else is entered in the following code.
def purchase():
while True:
try:
firstname, lastname, bus_row, bus_seat = input(
'Enter name first and last name and bus row and seat:').split()
print("Name: {} {}\nrow {} seat {}".format(firstname, lastname, bus_row, bus_seat))
with open('bookings.txt', 'a') as bookings:
bookings.write('\n' + firstname + " " + lastname + " " + bus_row + " " + bus_seat)
break
except ValueError:
print('Invalid entry')
return
purchase()