In my program using python, I'm giving the user choices and as long as those choices are made in order the program works great, but lets say the user chooses the 4th option, and then wants to go back and do the first option the program terminates. Here is the code for my program can anyone suggest how to make this work?
### start of program loop
def script():
### Welcome message
un = input('What is your name?\n')
print('Welcome to the Pizza Party Maker', un, '!\n')
print('This will create a guest list, with the items your guests are bringing to the party, and what pizza topping they want!\n')
### create dictionary
guests = {}
### input choice
choice = int(input('What would you like to do (1) Add a guest , (2) Remove a guest, (3) Update a guest, (4) See List, (5) Make a new list, (6) Exit\n'))
### add guest, item, and pizza topping to dictionary
while choice == 1:
gn = input('What is your guest''s name?\n')
print('What is', gn, 'bringing to the party?(salads, desserts, drinks, plates etc.)')
gi = input()
print('What pizza topping would', gn, 'like to have on his/her pizza?(Pepperoni, Cheese, Mushrooms, Onions, etc.)')
gt = input()
print()
guests[gn]=gi,gt
choice = int(input('What would you like to do (1) Add a guest , (2) Remove a guest, (3) Update a guest, (4) See List, (5) Make a new list, (6) Exit\n'))
### remove guest
while choice == 2:
gr = input('Which guest would you like to remove?\n')
del guests[gr]
print(gr, 'has been removed from your party!\n')
choice = int(input('What would you like to do (1) Add a guest , (2) Remove a guest, (3) Update a guest, (4) See List, (5) Make a new list, (6) Exit\n'))
### edit guest
while choice == 3:
gn = input('Which guest would you like to update?\n')
print('What is', gn, 'bringing to the party instead?(salads, desserts, drinks, plates etc.)')
gi = input()
print('What pizza topping would', gn, 'like to have on his/her pizza instead?(Pepperoni, Cheese, Mushrooms, Onions, etc.)')
gt = input()
print()
guests[gn]=gi,gt
choice = int(input('What would you like to do (1) Add a guest , (2) Remove a guest, (3) Update a guest, (4) See List, (5) Make a new list, (6) Exit\n'))
### show guest list (sorted alphabetical)
while choice == 4:
print('This is your guest list, what they are bringing, and what topping they want!')
for i in sorted (guests):
print((i, guests[i]), end = " ")
print()
choice = int(input('What would you like to do (1) Add a guest , (2) Remove a guest, (3) Update a guest, (4) See List, (5) Make a new list, (6) Exit\n'))
### Loop back to the beginning
while choice == 5:
if choice == 5:
script()
### End program
while choice == 6:
print('Thank you for using Mike\'s Pizza Party Maker!')
return
### not a valid choice
else:
print('That is an invalid choice, please try again.\n')
choice = int(input('What would you like to do (1) Add a guest , (2) Remove a guest, (3) Update a guest, (4) See List, (5) Make a new list, (6) Exit\n'))
script()
choiceas the function's parameter. Have the function run in a while loop or something untilinput = 'q'or not an int (i.e. choice).