We can use try except statements to have control over certain exceptions that are thrown.
We can chose how we want to handle the exception, in our case we dont want the program to shut down when a ValueError occurs.
In our case we will catch the error and ask the user to input the data in the right format until the user gets it correct.
while True:
user_input = input("Input {}: ".format(arr_col_name))
try:
user_input = wanted_type.type(user_input)
break # Break out of the loop if the conversion succeeds
except ValueError:
print("Wrong datatype. Please input a {}.".format(wanted_type))