user_input = input('How old are you?: ')
if user_input >= 18:
print('You are an adult')
elif user_input < 18:
print('You are quite young')
except ValueError:
print('Please type in an integer')
它说除了
之外的语法错误请帮忙。
答案 0 :(得分:1)
except
不与if/elif/else
一起使用。相反,它与try
一样,如下所示:
user_input = input('How old are you?: ')
try:
age = int(user_input) #this can raise ValueError
if age >= 18:
print('You are an adult')
elif age < 18:
print('You are quite young')
except ValueError:
print('Please type in an integer')