from random import randint
def main():
dob = int(input("Please enter the year you were born"))
if dob > (2005):
main()
elif dob < (2004):
main()
else:
def mob():
if dob == (2004):
month = input("Please enter the first three letters of the month you were born")
if month == ("Jan","JAN","jan","Feb","FEB","feb","Mar","MAR","mar","Apr","APR","apr","May","MAY","may","Jun","JUN","jun","Jul","JUL","jul"):
age = 12
elif month == ("Aug","AUG","aug"):
day = int(input("Please input the day you were born"))
if day < 28:
age = 12
elif day == ("29","30","31"):
age = 11
else:
age = 12
else:
age = 11
if dob == (2005):
age = 11
mob()
main()
如果我进入2004年,然后是8月,那就不会问那一天了出生代码将停止。我还希望代码能够运行,这样如果我进入2005年,它会将年龄指定为11岁
像这样的东西确实满足了你的需要,我想,尽管你可以通过使用datetime来进一步整理它以给出实际的年龄。你知道吗
更好的选择,涵盖了我认为最不可能发生的事情
相关问题 更多 >
编程相关推荐