thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

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

All courses

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.

More options

Your lesson progress

Walkthrough: not startedPractice: not started

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.

Rob compares two dog ages with empty returned-value slots.
Rob’s comic strip · Function challenges

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.

Expected output
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.

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.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

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

ONE STEP FORWARD

Compare your approach with the explained solution and original solution recording next.