FAQ: Lambda Function Code Challenge - Add Random

This community-built FAQ covers the “Add Random” exercise from the lesson “Lambda Function Code Challenge”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise Add Random

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


Not sure if this has been asked before, but in the case that I wanted to run this random function in something like PyCharm or VSCode, would I need to import a library/module? I’m just starting so I’m not sure what the correct terminology is, but I remember from my CS class in HS that in Java you had to import certain things for some functions to work.

Which code? There is no code nor exercise url in this FAQ, so i am uncertain of the code you ran/used

the random module:


does indeed need to be imported.

If you are talking about Python’s built in random then yes, you need to import it.

This is the 3rd module in a row that is broken. View solution gives you this:

Traceback (most recent call last):
File “script.py”, line 6, in
print add_random(5)
File “script.py”, line 4, in
add_random = lambda num: num + random.radint(1,10)
AttributeError: ‘module’ object has no attribute ‘radint’

add_random(num) = num + random.randint(1,10)

add_random = lambda num : num + random.randint(1,10)

what’s the difference between two of them?
when I used the first one, it didn’t work.

I want to know why it doesn’t work and why we should use ‘lambda’(I think I didn’t understand the function of ‘lambda’

thankfully we find additional information about lambda:


Lambda are anonymous functions, they don’t have a name

the first one (your add_random function), you forgot to use return to hand back the the data of the addition. Lambda has implicit return

Can Lambda function take more than one input?

If you mean parameters, then, yes. They are functions and behave in the same manner.

>>> area = lambda a, b: a * b
>>> area(3, 4)

Yeap! I meant parameters and thank you for answering.

1 Like