如果输入正确,程序只会超出出生日期。还有其他有效的方法吗?
while True:
user_input = input("Enter your date of birth in the following format DD/MM/YYYY: ")
DOB = user_input.split("/")
if len(DOB) == 3:
day = DOB[0]
month = DOB[1]
year = DOB[2]
try:
if int(day) in range(1,32) and int(month) in range(1,13) and int(year) in range(1900,2018):
print ("Thanks")
break
else:
continue
except:
print ("Try again")
else:
print ("Try again")