Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Square a number using lambdaE02. Convert a list of strings to integers with mapE03. Filter out falsy values from a listE

Problem No 1

Square a number using lambda

Easy

6 minute session

Summary

Write a small function that returns the square of an integer using a lambda expression.

Problem statement

Create a function named square(n) that returns the square of the integer n. Implement the squaring operation using a lambda expression inside your function (i.e., define a lambda and use it to compute the result). The function should accept integers and return their square as an integer.

Task

Practice creating and using a lambda to compute the square of a number and return the result from a function.

Examples

Square of 5

Input

square(5)

Output

25

Explanation

5 squared is 25.

Input format

A single integer n provided as the function argument.

Output format

An integer representing n * n.

Constraints

n will be an integer in the range [-10**6, 10**6]. Use a lambda expression to compute the square.

Samples

Sample input 0

square(-3)

Sample output 0

9

Explanation 0

-3 squared is 9.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

03:42 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.