FAQ: Lambda Function Code Challenge - Multiple of Three

This community-built FAQ covers the “Multiple of Three” 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 Multiple of Three

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!

I believe that this exercise contains an error in the example. The examples explain how to use modulo in the following (among other) example:

12%5 #5 is not a multiple of 12

I think that the author of this got confused and wrote the # comment backwards. While it’s true that 5 is not a multiple of 12, that is not proven by 12%5. It would be proven by 5%12. Using the logic of the exercise, 12%24 would return a remainder of 12 and conclude that 24 is not a multiple of 12 when it is.

In short, and please correct me if I’m just misunderstanding this, x%5 == 0 proves that x is a multiple of 5; it does not prove that 5 is a multiple of x.

Hello, @web1233442072. Welcome to the forum. I believe you are correct. It should read that '5 is not a factor of 12' or '12 is not a multiple of 5'. If you can provide a link to the specific exercise, I’ll submit a bug report. Good catch!

1 Like


Exercise 7/12 in Advanced Python.

Thank you for the response.

1 Like

I’ve submitted a report. We will see if it gets corrected.

1 Like

The author might be unaware that while a learner is typing in the code, the editor is assuming the str() function, and auto-inserting that syntax. Would throw any learner for a loop. This should not be the recommended or instructed name to use in the code.

@factoradic, something of note.


This is not on the topic, but on an earlier lesson leading up to it. I’m still not caught up yet.

Caught up. That is definitely a narrative issue. I’ve not seen the term, factor come up much. It does factor into this discussion, though; pun intended.

On the whole, we can complete this lesson, given our own intuition and can forgive the ambiguity in the narrative if we have our own wherewithal.

1 Like

Just FYI, but when I type str in the Codecademy editor it doesn’t auto-insert str(). Just tried it again to be sure.

Funny, it did for me. All the same, that variable name should not be used.

string_of_pearls = "pearl pearl pearl pearl pearl pearl pearl pearl"

The name describes the str object in readable terms. It’s not just a string, but an object that happens to be a string. Describe the object.

1 Like

lambda are meant to be expressive and precise.

#Write your lambda function here
rate_movie = lambda rating: rating > 8.5 and "I liked this movie." or "This was not very good."

print rate_movie(9.2)
print rate_movie(7.2)
I liked this movie.
This was not very good.

This will not pass the pass the SCT. Still working on that.

just like my solution to the exercise you linked.

long_string = (lambda f: lambda g: lambda x: f(g(x)))((lambda b: lambda a: a > b)(12))(len)

…they said to do it with lambda.

actual code it was derived from:

long_string = (>12) . length

Then I expanded the functions in that


And so you did. Wicked.

Funny, it let me pass, too. What’s different between the two?

I think the point is that they’re expressions, not that they are expressive. By being able to write function literals, they can be combined. Like with numbers. We have literals for those.
1 + 3

something = lambda f: lambda g: lambda x: f(g(x))
add1 = lambda x: x + 1
mul2 = lambda x: x * 2
something(add1)(mul2)(3) # 7

Nouns as opposed to adjectives. Makes sense.

if_ = lambda cond: lambda a: lambda b: lambda x: cond(x) and a() or b()
gt = lambda b: lambda a: a > b

rate_movie = \
  (lambda: "I liked this movie")
  (lambda: "This movie was not very good"))

print rate_movie(9.2)
print rate_movie(7.2)

Who needs built-in statements? Not us. Could even do away with the assignment statement. This is quickly becoming full-on lisp code…


OMG, are you trying to fry my mind? If so you are succeeding. Seriously, though, I am doing my best to follow along and love how you have this playing out. It’s poetry.

1 Like

In the code below;

#Write your lambda function here
multiple_of_three = lambda num : “not a multiple” if num %3 else “multiple of three”

print multiple_of_three(9)
print multiple_of_three(10)

I had "not a multiple and “multiple of three” reversed and it was wrong. But if I’m looking at this logically by putting %3 against “print multiple_of_three(9)” it would seem more correct to have “Multiple of three” first. Doesnt %3 end with a 0 sum? The logic just seems backwards to me.

def multiple_of_three(x):
    return not x % 3

The above will take the result of x mod 3 and cast it as a boolean then toggle it.

4 % 3  =>  1  =>  truthy

not 1  =>  False

9 % 3  =>  0  =>  falsy

not 0  =>  True

Using the above logic, and knowing that return is implicit in lambda, how would we write the above?