On Dictionary | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

On Dictionary

Pls I tried this code: food={ "Lettuce":5, "Carrot":4, "Mango":10, "Chesseburger":0,} count=0 foods=input() y=foods.split(" ") for i in y: z=food.get(i) count=count+z print(count) >>It didn't work on Solo learn but did on my laptop .it is a practise question Izzy iguana on code coach Thank u

25th Dec 2022, 11:11 PM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
11 Answers
+ 1
What does Sololearn say? Also, you don't need comma in the last dictionary item, since there are no more items afterwards
25th Dec 2022, 11:21 PM
Lamron
Lamron - avatar
+ 1
It works you just didnt do the check if it greater then some value print something not the sum reread the problem
25th Dec 2022, 11:43 PM
Ion Kare
Ion Kare - avatar
+ 1
Try this. snacks = input() s_snacks = snacks.split() count = 0 points = { "Lettuce": 5, "Carrot": 4, "Mango": 9, "Cheeseburger": 0 } #iterate available snacks for s_snack in s_snacks: if s_snack in points: count += points[s_snack] if count >= 10: print("Come on Down!") else: print("Time to wait")
26th Dec 2022, 5:05 AM
Mwaüra
0
Ion Kare sorry I dont understand wht ur saying
26th Dec 2022, 12:45 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
0
Oyedeji Hiqmat "You need 10 total snack points to bring it down. Lettuce is worth 5, Carrot is worth 4, Mango is worth 9, and Cheeseburger is worth 0." "Task: Evaluate whether or not you have enough snack points to convince your iguana to come down." "Output Format: A string that says 'Come on Down!' if you have enough points, or 'Time to wait' if you do not. "
26th Dec 2022, 12:49 AM
Ion Kare
Ion Kare - avatar
0
Ohh I didnt finish it
26th Dec 2022, 1:00 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
0
Ion Kare but thanks
26th Dec 2022, 1:01 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
0
Mwaüra thank u very muh
26th Dec 2022, 7:42 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
0
Mwaüra didnt have to change the whole code , he just needed to remove the print(count) with -> if count >= 10 : print("come on down") else: print("time to eat")
26th Dec 2022, 5:34 PM
Ion Kare
Ion Kare - avatar
0
Hello
26th Dec 2022, 6:22 PM
Abhay Mali
Abhay Mali - avatar
0
Answers
8th Jan 2023, 4:51 AM
Thameesh Ahamed
Thameesh Ahamed - avatar