I’m working on Izzy the Iguana code coach challenge. My code work for all but 1 test case. What am I missing?!?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I’m working on Izzy the Iguana code coach challenge. My code work for all but 1 test case. What am I missing?!??

Unfortunately the test case was locked so I can’t even see what was inputted but here is my code: https://sololearn.com/compiler-playground/ccD7h194LPb4/?ref=app

7th Oct 2023, 3:38 AM
Josh Rhodes
13 Answers
+ 6
Josh Rhodes A hint: You iterate in for loop over the items of the list but each time don‘t check the item only whole list.
7th Oct 2023, 6:21 AM
JaScript
JaScript - avatar
+ 6
Josh Rhodes , yes this was intended solution. Here inclusive a few improvements: snacks = input().split() pts = 0 for i in snacks: if i == "Lettuce": pts = pts + 5 elif i == "Carrot": pts = pts + 4 elif i == "Mango": pts = pts + 9 else: continue if pts >= 10: print("Come on Down!") else: print("Time to wait")
7th Oct 2023, 8:49 PM
JaScript
JaScript - avatar
+ 5
Josh Rhodes , your code is built like this: snacks = input().split() pts = 0 for i in snacks: if "Lettuce" in snacks: pts = pts + 5 ... one test fails. as JaScript already mentioned, the iteration you use should be modified for all cases. we can do it like: snacks = input().split() pts = 0 for i in snacks: if i == 'Lettuce': pts = pts + 5 ...
7th Oct 2023, 1:20 PM
Lothar
Lothar - avatar
+ 4
Rik Wittkopp , the code can be seen on windows pc but not on mobile devices. it is not dependend on having pro.
7th Oct 2023, 1:21 PM
Lothar
Lothar - avatar
+ 3
Can you show your attempt The link to the challenge is not connecting, pro subscription required. Also, what are the requirements of the challenge
7th Oct 2023, 4:44 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Thanks for all the tips and hints guys but I finally solved it with an easy fix. Heres the new code: https://code.sololearn.com/ccD7h194LPb4/?ref=app
7th Oct 2023, 6:21 PM
Josh Rhodes
+ 2
Josh Rhodes I found the challenge, so if you show your attempt, I can review and assist
7th Oct 2023, 4:46 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Josh Rhodes, post your code with this description. https://code.sololearn.com/Wek0V1MyIR2r/?ref=app
7th Oct 2023, 4:48 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 2
Wong Hei Ming I figured out how to post the correct url. I have to add “code.” before “sololearn” and then delete “compiler-playground”. https://code.sololearn.com/ccD7h194LPb4/?ref=app
9th Oct 2023, 7:47 PM
Josh Rhodes
+ 1
Josh Rhodes, congratulation you pass this exercise. Below is the code to use a dictionary, along with comments to help you learn. # Lettuce is worth 5, Carrot is worth 4, Mango is worth 9, and Cheeseburger is worth 0 foods = {"Lettuce": 5, "Carrot": 4, "Mango" : 9, "Cheeseburge": 0} snacks = input() snacks = snacks.split() points = 0 ''' use the dictionay get() method the first argument is the key and second argument is the return value if the key is not found ''' for snack in snacks: point = foods.get(snack, 0) points += point ''' For the last 2 lines you can write like this: points += foods.get(snack, 0) However, it takes some time to understand the code It is bette to make the code simple and easier to debug with ''' if points >= 10: print("Come on Down!") else: print("Time to wait")
8th Oct 2023, 4:53 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
If you already reach Collection Type in the intermediate course, you will find using a dictionary is a better choice in this challenge.
7th Oct 2023, 6:24 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Helo guys am kindly requesting anyone who can help me code
7th Oct 2023, 7:33 PM
Joan Atieno
Joan Atieno - avatar
0
My first idea was to use a dictionary but I couldnt figure out how to call all the values and add them together. So I solved it the only other way I could think of.
7th Oct 2023, 7:57 PM
Josh Rhodes