我正在尝试计算一个人的年龄,以验证他是否已达到退休年龄。这是python 2.7
from datetime import datetime
def getName():
name = input("What is your name?: ")
return name
def getAge():
age = input("How old are you?: ")
return int(age)
def ifOrNot():
retirementAge = 65
if(getAge() >= retirementAge):
print("Hello ",getName(), ", are you in retirment age")
else:
timeToRetirement = retirementAge - getAge()
print("Hello ", getName(), " are you not in retirement age, you need to wait ", timeToRetirement, " more").
def main():
ifOrNot()
main()
“你多大了”这个问题在屏幕上出现了两次。然后显示一次“你叫什么名字”这个问题。然后是这些错误:
Traceback (most recent call last): File "main.py", line 22, in
<module>
main() File "main.py", line 20, in main
ifOrNot() File "main.py", line 17, in ifOrNot
print("Hola ", getName(), " aun no estas en edad de retiro, te faltan ", timeToRetirement) File "main.py", line 4, in getName
name = input("What is your name?: ") File "<string>", line 1, in <module> NameError: name 'Diesan' is not defined
我想先问名字,再问年龄,然后计算出能够退休的剩余年限。奇怪的是,我不需要使用datetime,对吧?
芜湖不芜
森林海
相关分类