Y’all are amazing, thank you!!! I was able to get myself unstuck. I would like to share the exercise I was working on and what I was able to do in order to finish the project. I was struggling to get my_age to hold it’s value.
Instructions:
- The function
calculate_age
in script.py creates a variable called age
that is the difference between the current year, and a birth year, both of which are inputs of the function. Add a line to return age
.
- Outside of the function, call
calculate_age
with values 2049
( current_year
) and 1993
( birth_year
) and save the value to a variable called my_age
.
- Call
calculate_age
with values 2049
( current_year
) and 1953
( birth_year
) and save the value to a variable called dads_age
.
Print the string "I am X years old and my dad is Y years old"
to the console, with my_age
where the X
is and dads_age
where the Y
is.`
-------------------------------------code-------------------------------------
I am adding below the code I did:
def calculate_age(current_year, birth_year):
age = current_year - birth_year
return (age)
current_year = 2049
#originally put as ‘birth_year: 1993’ to calculate my own birth year, then I couldn’t figure out how to get it to hold the value as my_age so I changed the birth year to 1953 in order to calculate dads_age
birth_year = 1953
#my age - uses birth year 1993 ( later changed to 1953 to get dads_age so I added a result to hold the value
my_age = (current_year - birth_year)
my_age_result = 56
print(str(my_age_result))
#dads
dads_age = (current_year - birth_year)
print(str(dads_age))
dads_age_result = 96
#printing statement
print ("I am ", my_age_result, "years old and my dad is ", dads_age_result, “years old!”)
What I got:
56
96
I am 56 years old and my dad is 96 years old!
Did I format the code in the correct way? Especially when changing my_age to dads_age and having to use both in the final statement…I was struggling pretty hard with understanding why I couldn’t just get the code to remember my_age
Thank you for your contributions!! Without you all, I would’ve still been stuck!