我制作这个出生日期计划可以让它更有效率吗?

时间:2017-11-08 21:29:26

标签: python-3.x

如果输入正确,程序只会超出出生日期。还有其他有效的方法吗?

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")

0 个答案:

没有答案