Computer Science/Lesson 3 Flow, Data, Iteration/Python Code Challenges: Lists/More_than_n

There’s something wrong with the checking part. It gives a different list from what is in the code.

Are you saying your function is only supposed to work for one specific input?

If so you could write it like this:

def more_than_n(lst, item, n):
    return True

Otherwise, the error message is making a valid point, isn’t it?

Hello @ethicallycute, are you reading the instructions properly?

If you think you are, check this out:

The exercise is asking for you to check a list (lst) for a value (item), and return True if the item appears in the list more than n times.

If you're still stuck:

For example, when checking this list:

list1 = [1, 2, 2, 1, 2, 2, 1]
#for the object 1
def more_than_n(lst, item, n):
  #some code
print(more_than_n(list1, 1, 2))
#This should print-once you've filled in the code-True. That is because the object 1 appears in the list more than twice.

I hope this helps!

1 Like

If you look at the very bottom, right next to the “check answer” button, you will see a message that gives a different lst than what is provided. Even when I use the list in the message it still says the answer is incorrect. When I use the solution provided, which also outputs “True”, it says it is correct.

If you look at the very bottom, right next to the “check answer” button, you will see a message that gives a different lst than what is provided. Even when I use the list in the message it still says the answer is incorrect. When I use the solution provided, which also outputs “True”, it says it is correct.

It’s telling you about an input for which your function responds incorrectly.

It’s telling you what the result should be. It’s telling you what response you do give, which is different. It’s also telling you about what input was used.

The input that I was given: print(more_than_n([2, 4, 6, 2, 3, 2, 1, 2], 2, 3))
The input that they gave: print(more_than_n([2, 3, 4], 2, 1))

I had a problem with one other question that gave me an error too. I didn’t have any issues with the other problems and was able to get the other ones correct with the input that they gave. I posted this to alert mods to see if there was something wrong with the check answer code.

Well that message is entirely accurate. Your functions behaviour is indeed wrong for the input shown in that message.

Whether or not you also used that input is beside the point. The point is that an input was found that your function behaves incorrectly for.

Can you dissect it, and point out where it is “indeed wrong”? I’m looking at it, and I disagree.

If we disagree on what the result should be then we probably disagree on what the function should do as well. What should it do? What’s asked for?

You’re avoiding the question, and I’m not sure why since you see how it is “indeed wrong”. Can you point out where it is wrong and how it is wrong?
error

yes because you’re avoiding the information you already have so I’m referring to them

what do the instructions ask you to do with that input?

Also, thank you for your response and answer. It was very helpful.

1 Like

print(more_than_n([2, 4, 6, 2, 3, 2, 1, 2], 2, 3). Does this print out True or False?

What information am I avoiding, and what are you referring to? I’m only trying to understand.

For the instructions: print(more_than_n([2, 4, 6, 2, 3, 2, 1, 2], 2, 3). Does this print out True or False?

Yes, that should print True, since the number 2 (item) appears more than 3 times (n) in the list (lst) `[2, 4, 6, 2, 3, 2, 1, 2].

Okay, I’m confused then. If the output is supposed to print out True, and my code prints out True, how is my code indeed wrong?

You’re getting the correct output for more_than_n([2, 4, 6, 2, 3, 2, 1, 2], 2, 3), but only by mistake, like using an incorrect formula in mathematics but still getting the right answer. When codecademy tests more_than_n([2, 3, 4], 2, 1)) with your code it gets an incorrect output. Make sure you’re reading the prompt correctly and match your conditional if statement accordingly.

That’s the thing though. I was given this output

when I did the assignment.

I was not given

So I am unsure as to why it was popping up.

With the code challenges, behind the scenes Codecademy is testing a few other function calls with different arguments to see if your code is correct for all scenarios.

more_than_n([2, 3, 4], 2, 1) is one of the scenarios where you’re code failed.