my program takes a mathematical input and checks it for errors before proceeding, here is the part of the code I need help with:
expression= introduction()#just asks user to input a math expression
operators= set("*/+-")
numbers= set("0123456789")
for i in expression:
while i not in numbers and i not in operators:
print("Please enter valid inputs, please try again.")
expression= introduction()
Now I have set up an error loop but the problem I am having is that I don’t know what to update the loop with in this scenario. Anyone?
I need something simple such as the “while True” code in the answers below. The rest are too advanced. I need something close to the code that is posted in this OP.
I would do it something like this:
You only want to call
introduction()once per badexpression. The way you do it now, you are callingintroduction()for every invalid character inexpression.