04.02 · Transform and filter values / Practice · 7 min
Return a square for each argument
Squaring means multiplying a number by itself, not doubling it.
Activity 2 of 6 in Transform and filter values
Python 3: Lists / 04.02
Practice lambda results
Not started
Use the source square task, then check a second call with a negative argument.
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
Change square so it returns the square of its number argument. Use a one-expression lambda for this exercise. Keep seven_result = square(7) and negative_result = square(-3).
Print seven_result followed by negative_result. Expect 49 and 9, not 14 and -6. The checks inspect both stored call results and output; they do not distinguish lambda syntax from an equivalent def function.
Predict before running
A negative number squared is positive because the two negative factors are multiplied. After passing, try square(0), square(1) and square(2.5). Restore the two original calls for the fixed checks.
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
Return the square, not the double
Change square to a one-expression square function. Keep its calls for 7 and -3 and print their stored results, 49 then 9.
49 9
Keep the starting inputs. Print these lines in this order, without extra output.
- Store the requested seven result
- Store the requested negative result
- Output 1 matches the requested result
- Output 2 matches the requested result
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?
Square is not double
Multiply number by itself or raise it to the power 2. Let the expression use its argument.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
Each call calculates from its own argument. The expression’s value is returned without a return statement inside the lambda.
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 2
Read the original inputs
Identify the original values before choosing the transformation or keep rule.
square = lambda number: number ** 2Expected output for this step
(No output)
Apply the function and inspect each result
Each call calculates from its own argument. The expression’s value is returned without a return statement inside the lambda.
square = lambda number: number ** 2
seven_result = square(7)
negative_result = square(-3)
print(seven_result)
print(negative_result)Expected output for this step
49 9
See the complete solution
square = lambda number: number ** 2
seven_result = square(7)
negative_result = square(-3)
print(seven_result)
print(negative_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