I am trying to calculate the age of a person, to verify whether or not he is of retirement age. This is 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()
The question "how old are you" appears on the screen twice. Then the question "What's your name" is displayed once. And then these errors:
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
I want to ask for the name first, then the age, and calculate the remaining years to be able to retirement.
Curiosly, I do not need to use datetime
, right?