06.02 · Function challenges / Practice · 12 min
Return a human-age equivalent for each dog
Two calls use the same function. Each argument should produce its own returned value.
Activity 2 of 4 in Function challenges
Python 2: Logic, Loops & Functions / 06.02
Build the dog-age converter
Not started
Apply the original dog-age formula and return reusable numeric results.
Your lesson progress
Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Your task: calculate, return and keep both calls
Keep calculate_human_age(dog_age). Replace return 0 with the supplied calculation: (dog_age - 2) * 4 + 21. You may store the calculation in a local name or return it directly.
Keep the calls using 5 and 10, their result variables and the two print calls. The stored results must be 33 and 53, with only those two lines printed in that order. Do not print from inside the function or hardcode the two answers.
Test the function beyond the starter
The visible checks inspect the fixed caller values and complete output; they do not prove the algorithm or every possible input. After passing, try ages 2, 3 and 7: expect 21, 25 and 41. Restore the original two calls before checking the challenge.
This supplied formula is scoped to ages 2 and above. Handling younger ages or a different model would be a separate specification.
Build it one step at a time
Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)3 steps · Saved work · Instant feedback
YOUR TURN
Convert dog age to a human-age equivalent
Keep calculate_human_age(dog_age), the calls for 5 and 10 and the supplied caller names. Apply (dog_age - 2) * 4 + 21 and return a number. Print only 33 and 53, in order.
33 53
Keep the starting inputs. Print these lines in this order, without extra output.
- Store 33 for dog age 5
- Store 53 for dog age 10
Edit Python, then run it. Check challenge checks your output and the listed Python requirements. Your code saves on this browser after a short pause. Sign in and choose Save account draft to keep it across devices. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Need a nudge?
Group the subtraction first
Without parentheses, multiplication happens before subtraction. Keep dog_age - 2 together, then scale that result and add 21.
Give the answer back
The caller assigns the value of the function call. Use return inside the function; leave display to the two existing print calls.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
One definition handles both ages. Parentheses control the calculation, and return makes the result available to the caller.
Walk through the fix.
Choose Next to inspect one change at a time. Highlighted lines show what to notice. Your editor stays unchanged unless you choose to load a step.
Step 1 of 3
Trace a single input
For a dog age of 5, subtracting 2 gives 3. Multiplying by 4 gives 12, then adding 21 gives 33. This traces the formula before placing it in the function.
dog_age = 5
remaining_years = dog_age - 2
human_age = remaining_years * 4 + 21
print(human_age)Expected output for this step
33
Return the computed value
The parameter gets the argument for each call. human_age is local to that call; return gives its number to the caller.
def calculate_human_age(dog_age):
human_age = (dog_age - 2) * 4 + 21
return human_age
result = calculate_human_age(5)
print(result)Expected output for this step
33
Reuse the definition
Both caller variables use the same function, with different arguments. No print belongs inside the function for this task.
def calculate_human_age(dog_age):
human_age = (dog_age - 2) * 4 + 21
return human_age
five_year_result = calculate_human_age(5)
ten_year_result = calculate_human_age(10)
print(five_year_result)
print(ten_year_result)Expected output for this step
33 53
See the complete solution
def calculate_human_age(dog_age):
human_age = (dog_age - 2) * 4 + 21
return human_age
five_year_result = calculate_human_age(5)
ten_year_result = calculate_human_age(10)
print(five_year_result)
print(ten_year_result)Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in