check input must be less than 241 characters pyhotn code example
Example 1: python check if input() gives error
try:
age = int(input("Please enter your age: "))
except ValueError:
print("Sorry, I didn't understand that.")
else:
if age >= 18:
print("You are able to vote in the United States!")
else:
print("You are not able to vote in the United States.")
Example 2: python double check if wants to execute funtion
while True:
try:
age = int(input("Please enter your age: "))
except ValueError:
print("Sorry, I didn't understand that.")
continue
else:
break
if age >= 18:
print("You are able to vote in the United States!")
else:
print("You are not able to vote in the United States.")