Activity:
Create a program that accepts birth year and current year. Define a function that has 2 parameters: birthyear
and presentyear then it will calculate and returns the age. Define another function that will determine if the
age is minor or legal age.
FINISHED CODE:
def getAge():
def validateAge():
byear = int(input("Enter Birth Year:"))
pyear = int(input("Enter Present Year:"))
age = getAge()
validatedAge = validateAge()
print(f "Your age is {age} and it is {validatedAge}")
sample output:
Enter Birth Year: 1992
Enter Present Year:2021
Your age is 29 and it is legal
def getAge():
byear = int(input("Enter Birth Year:"))
pyear = int(input("Enter Present Year:"))
currentAge = pyear - byear
return currentAge
def validateAge(age):
if (int(age) >= 18):
status = "legal"
else:
status = "minor"
return "Your age is " + str(age) + " and it is " + status
print(validateAge(getAge()))
Comments
Leave a comment