def count_years(current_age, age_goal):
years = 0
age = current_age
while age < age_goal:
years += 1
age += 1
return years
def main():
print( count_years(20, 35))
main()
15
while
loopYou need to determine two things:
Write a while loop to count how many years until you can run for president (simplistic example, for illustration purposes only):
.format()
methodLet’s update our function so it returns a string message instead of an integer:
def count_years(current_age, age_goal):
years = 0
age = current_age
while age < age_goal:
years += 1
age += 1
message = "It will take {} years".format(years)
message += " for you to be able to run for president."
return message
def main():
print( count_years(20, 35))
main()
It will take 15 years for you to be able to run for president.
Use :
to specify formatting options,
Instructions for Short Project of the Week