05.04 · Functions, defaults and scope / Practice · 7 min
Repeat text twice unless the caller chooses a count
The custom call works, but the call without a count repeats only once. The fallback is wrong.
Activity 4 of 6 in Functions, defaults and scope
Python 2: Logic, Loops & Functions / 05.04
Practice default arguments
Not started
Repair the default while preserving an explicitly supplied repetition count.
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: repair the default, not the callers
Keep repeat_string(string, times) as the function’s parameter names, keep the string * times return expression, and set the default for times to 2. Keep custom_result assigned from repeat_string("hi", 3) and default_result from repeat_string("bye").
The two supplied print calls must display hihihi and byebye in that order. The explicit count of 3 must still override the default. Do not hardcode a repetition count in the return expression.
Try an explicit count of zero
The fixed-input checks inspect both stored strings and the complete output for the two calls. They do not prove every argument or the syntax used. After passing, try repeat_string("ha", 0): it should return an empty string. repeat_string("ha") should return haha, and repeat_string("ha", 1) should return ha. Restore the starter calls before checking again.
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
Choose the fallback repetition count
Keep repeat_string, the string * times return expression, both supplied calls and both print calls. Set times to default to 2 while keeping an explicit count of 3 effective for the custom call.
hihihi byebye
Keep the starting inputs. Print these lines in this order, without extra output.
- Keep custom_result as hihihi
- Store byebye in default_result
- Print the custom repetition first
- Print the default repetition second
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?
The fallback belongs in the signature
The caller that supplies 3 already works. Change the default in the parameter definition instead of forcing every call to repeat twice.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
The default applies only when times is omitted. A supplied 3 still means three repetitions, and a supplied 0 still means zero repetitions.
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
Use the default when the count is missing
The function binds times to 2 because this call supplies only the string. Returning string * times gives byebye.
def repeat_string(string, times=2):
return string * times
print(repeat_string("bye"))Expected output for this step
byebye
Honor a supplied count
This call supplies 3, so the default is not used. The same function returns hihihi.
def repeat_string(string, times=2):
return string * times
print(repeat_string("hi", 3))Expected output for this step
hihihi
Keep both caller paths working
One definition serves both calls. The custom call does not rewrite the default for the next call.
def repeat_string(string, times=2):
return string * times
custom_result = repeat_string("hi", 3)
default_result = repeat_string("bye")
print(custom_result)
print(default_result)Expected output for this step
hihihi byebye
See the complete solution
def repeat_string(string, times=2):
return string * times
custom_result = repeat_string("hi", 3)
default_result = repeat_string("bye")
print(custom_result)
print(default_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