【发布时间】:2021-01-10 12:52:53
【问题描述】:
我一直在尝试编写这段代码,如果某个输入不正确,我需要一种停止代码的方法,这是我目前所拥有的:
first_name = input('PLEASE ENTER YOUR FIRST NAME: ')
last_name = input('PLEASE ENTER YOUR SURNAME: ')
print(f'Hello {first_name} {last_name}, before you enter.')
def age_det():
age = input(f'How old are you?')
converted_age = [int(age)]
for num in converted_age:
while num>=18:
print(f'Awesome, {first_name}, welcome to Blablabla')
num += 100
while num <= 18:
break
print(f'Sorry, {first_name}, but we require you to be at least 18 to enter Blablabla.')
num += 100
age_det()
#I want the code to stop here if the age entered is under 18
username = input('Before we start, please pick a username: ')
print(f'Woah! {username}, good choice!')
【问题讨论】:
-
if age < 18: sys.exit(1)...
标签: python