Izzy the Iguana Issue - Test Case 4 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Izzy the Iguana Issue - Test Case 4

I have the following code written for the Iguana issue yet test case 4 keeps failing, I know you can do this in other ways e.g. for n in snacks, if n == 'Lettuce' or writing a dictionary and use .get. But I want to know why this doesnt work CODE snacks = input() snacks = snacks.split() total = 0 for n in range(len(snacks)): if 'Lettuce' in snacks: total += 5 elif 'Carrot' in snacks: total += 4 elif 'Mango' in snacks: total += 9 elif 'Cheeseburger' in snacks: total += 0 if total >= 10: print ("Come on Down!") print (total) else: print ("Time to wait")

15th Jul 2023, 7:42 PM
Owain Hayes
Owain Hayes - avatar
5 Answers
+ 8
Owain Hayes , there are several issues that should be fixed: > the for loop is generating numbers that are never used. better to run the loop like: for snack in snacks: ... > the conditional statements should now be compare the *snack* variable like e.g.: if snack == 'Mango': ... > when printing the output, we should *not* use the line: # print(total) this output is not required.
15th Jul 2023, 8:41 PM
Lothar
Lothar - avatar
+ 7
Have you run the code yourself in the code playground? What happens if there are 2 or more of one of the items?
15th Jul 2023, 7:59 PM
Ausgrindtube
Ausgrindtube - avatar
+ 6
Owain Hayes , the code fragment in your last post should be: for n in snacks: if n == 'Lettuce': .... or better use a meaningful variable name: for snack in snacks: if snack == 'Lettuce': ....
16th Jul 2023, 11:04 AM
Lothar
Lothar - avatar
+ 1
Lothar yeah so like I already mentioned in my post? “for n in snacks, if snacks == ‘Lettuce’?” I am just wondering why this particular code doesnt fulfill all requirements? Whilst it could be done alrernatively as I mentioned, I dont see whats wrong with it functionally? Also yeah my bad I just ran that in a test to see if it was generating the totals correctly, in my attempts print(total) was not included
16th Jul 2023, 9:07 AM
Owain Hayes
Owain Hayes - avatar
0
Ausgrindtube, yeah I did that and it still runs fine, thats why I cant figure out what test case 4 could be that is leading to the fail
16th Jul 2023, 9:03 AM
Owain Hayes
Owain Hayes - avatar