I have a simple ice cream program, everything works. But how do I loop a single input like scoops if the input is invalid? Currently if the input is incorrect it re-asks the user for the first input again. Meaning if I enter vanilla for the flavor and 7 for the number of scoops, it will print the error message, then instead of re-asking how many scoops you'd like, it asks you what flavor you'd like. How would I fix this for my three inputs throughout the program? I would still like the program to restart after a valid order is entered. Thank you for your time.
Program code:
#Error for wrong flavor selection
class FlavorError(Exception):
def __init__(self, flavors, message):
Exception.__init__(self, flavors, message)
self.flavors = flavors
#Error for wrong number of scoops selection
class ScoopsError(Exception):
def __init__(self, scoops, message):
Exception.__init__(self, scoops, message)
self.scoops = scoops
#Error for wrong carrier selection
class HoldingsError(Exception):
def __init__(self, holdings, message):
Exception.__init__(self, holdings, message)
self.holdings = holdings
def main():
#Creating Values
flavors= " "
scoops = " "
holdings = " "
while True:
try:
#MENU / INFORMATION
print("Flavors: vanilla, chocolate, strawberry, mint, pistachio, and spumoni")
print("Number of scoops: 1, 2, 3")
print("Ways to eat: bowl or cone")
print()
#FLAVOR INPUT
flavors = input("Enter a flavor of ice cream: ").lower()
print()
#ERROR CHECK
if flavors not in ['vanilla', 'chocolate', 'strawberry', 'mint', 'pistachio', 'spumoni']:
raise FlavorError(flavors, "is not on the menu.")
#NUMBER OF SCOOPS INPUT
scoops = int(input("Enter the number of scoops: "))
print()
#ERROR CHECK
if scoops > 3 or scoops <= 0:
raise ScoopsError(scoops, 'We do not offer that many scoops!')
#CARRIER INPUT
holdings = input("Would you like a cone or bowl? ")
print()
#ERROR CHECK
if holdings not in ['bowl', 'cone']:
raise HoldingsError(holdings, 'Please select between a bowl or a cone')
print(scoops , "scoops of" , flavors , "in a" , holdings)
print()
except Exception as e:
print("Invalid choice! try again!"+str(e))
print()
main()