+ 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
13 Antworten
+ 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.
+ 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")
+ 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
...
+ 4
Rik Wittkopp ,
the code can be seen on windows pc but not on mobile devices. it is not dependend on having pro.
+ 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
+ 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
+ 2
Josh Rhodes
I found the challenge, so if you show your attempt, I can review and assist
+ 2
Josh Rhodes, post your code with this description.
https://code.sololearn.com/Wek0V1MyIR2r/?ref=app
+ 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
+ 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")
0
If you already reach Collection Type in the intermediate course, you will find using a dictionary is a better choice in this challenge.
0
Helo guys am kindly requesting anyone who can help me code
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.