I am learning Python and enjoying the challenges so far.
I am confused about why I keep getting the incorrect answer for this question. It keeps returning True, when it should return False. I think the issue is that the function is telling the computer to return False if there are more items than n’s in the list, and it can’t find the “n” at all - there’s no 1 in the list! I checked the answer and saw how to create the correct function. I just want to know why mine is wrong. Thanks!
Create a function named
more_than_nthat has three parameters named
The function should return
itemappears in the list more than
ntimes. The function should return
> def more_than_n(lst, item, n): > if lst.count(item) > lst.count(n): > return True > else: > return False > print(more_than_n([2, 3, 4], 2, 1)) > > #Uncomment the line below when your function is done > #print(more_than_n([2, 4, 6, 2, 3, 2, 1, 2], 2, 3))