The code is working well now, except when the user attempts to enter a string (or float) instead of an integer when being asked pizza questions.
Ideally I would like for the question to be repeated and not to exit the function. I assume this is possible with loops but I'm not sure how to go about doing that here.
Otherwise simply hopping out of the function to start from scratch is fine too. The problem is that when this happens, it ends up still trying to return later information which has now been botched (I don't even know how since they should have updated upon the most recent iterations)
I tried just return
as well as return None
.
def get_pizza_info(size, meats, veg, quantity):
try:
size = int(input("Enter size from 1-3: "))
except ValueError:
print("Error, please enter a whole number. ")
get_pizza_info(size, meats, veg, quantity)
return None
try:
meats = int(input("Enter number of meat toppings "))
except ValueError:
print("Error, enter a whole number. ")
get_pizza_info(size, meats, veg, quantity)
return None
try:
veg = int(input("Enter number of non-meat toppings "))
except ValueError:
print("Error, enter a whole number. ")
get_pizza_info(size, meats, veg, quantity)
return None
try:
quantity = int(input("Enter number of these pizzas "))
except ValueError:
print("Error, enter a whole number. ")
get_pizza_info(size, meats, veg, quantity)
return None
if size >= 4:
size = 3
if size <= 1:
size = 1
if meats <= 1:
meats = 1
if veg <= 1:
veg = 1
return size, meats, veg, quantity