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")
5 Respostas
+ 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.
+ 7
Have you run the code yourself in the code playground? What happens if there are 2 or more of one of the items?
+ 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':
....
+ 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
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