0

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
John Collins
  • 2,067
  • 9
  • 17
Grelm
  • 55
  • 1
  • 7
  • Alright, well @Grelm, here is an answer that may help you, let me know if you any questions : https://gist.github.com/jcollins-bioinfo/09981c45354740bdb31d1b13219bd8ec – John Collins Oct 26 '21 at 09:16
  • @martineau Thank you for pointing that out, I must have copied by mistake an older version of the code and not the final, which I had tested. I have updated the gist. It does indeed use recursion. Considering all the time you've put in helping us with this specific problem, it remains confusing why you closed it. – John Collins Oct 26 '21 at 12:03

0 Answers0