Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
This can be done using "exception handling," found in the section of the app "Exceptions and Files". Refer to that for more information. If you haven't yet reached it I wouldn't worry about it, but you could always look up more online! Here's the revised code to create an exception to the ValueError (when the input is not an integer): while True: try: x = int(input("Enter number: ")) while x <= 30: print(x) x = x + 1 if x >= 30: print("Finished") quit() except(ValueError): print('Error, not a valid number. Try again...') I hope that helps! I know I changed around in the code though, lmk if you have questions. Good luck!
23rd Jun 2016, 2:32 AM
Dean
0
there is also isdigit which checks to see if something is a digit that can help.
30th Jun 2016, 11:45 PM
Douglas Kohn
Douglas Kohn - avatar