Check out this link to read about exception handling. In a nutshell, you can use
The example below will exit the while loop if both input variables are successfully converted to integers, but will print the try again message if a
try
to attempt code that may cause an exception, and except
to execute code only if an exception is encountered.The example below will exit the while loop if both input variables are successfully converted to integers, but will print the try again message if a
ValueError
exception occurs.while True: rows_input = input("Enter Rows: " ) cols_input = input("Enter Cols: " ) try: rows = int(rows_input) cols = int(cols_input) break except ValueError: print("you have to Enter a Number not string... [Try again]")