Jun-18-2024, 08:00 PM
Not necessarily the only answer. I think there would be more elegant ways to solve the problem but this
while
loop will do the trick in your case.# assume an error error = True # while there is an error, repeat over and over again while error == True: try: num1 = int(input('Enter first number: ')) num2 = int(input('Enter second number: ')) c_answer = (num1 / num2) # change error to False, while loop stops error = False except ZeroDivisionError as e: print(dir(e)) # in this case a bit redundant (error already assumed), but error remains True on exceptions error = True