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

Checking your account…

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

All courses

Python 3: Lists / 04.02

Practice lambda results

Not started

Use the source square task, then check a second call with a negative argument.

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 sends 7 into a square function, calculates 7 times 7 and receives 49.
Rob’s comic strip · Transform and filter values

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.

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

Need a nudge?

Square is not double

Multiply number by itself or raise it to the power 2. Let the expression use its argument.

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

The same expression handles different arguments. Returning a calculated result makes the function reusable.