Python练习
任务
出生日期计算器
要定义age和name变量,我可以在文档开始时进行此操作,并为其指定占位符值。
age = - 1 # This is so I know immediately if something has gone wrong with later assignments
name = ""
相反,我选择了在接受用户输入时声明变量。 这使我更容易检查用户的输入。
while True :
age_input = input ( "How old are you? " ) # don't forget to cast into an int!
if age_input . isdigit (): # if the age entered is a digit, then we can move onto the next part of