I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:
def Release(): try: print 'Please select one of the following?\nCompletion = 0\nRelease ID = 1\nVersion ID = 2\nBuild ID = 3\n' a = int(input("Please select the type of release required: ")) if a == 0: files(a) elif a == 1: files(a) elif a == 2: files(a) elif a == 3: files(a) else: raise 'incorrect' except 'incorrect': print 'Try Again' except: print 'Error' Release()
I am also getting an error about the exception I have entered:
kill.py:20: DeprecationWarning: catching of string exceptions is deprecated except 'incorrect': Error
Thanks for any help
There is no do-while loop in Python.
I hope you could help me. I'm not sure to understand the detail of your code, but you can break out of a loop using the break keyword. For example you can do if ...: break , replacing ... with the condition that will allow to exit the loop. If you keep adding to count it will never break out.
def files(a): pass while True: try: i = int(input('Select: ')) if i in range(4): files(i) break except: pass print '\nIncorrect input, try again'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With