+ 2

Code coach — Izzy the Iguana — python — help and guidance.

Hello people. I need help with solving code coach challenge — Izzy The Iguana, using python language. I have produced this piece of code. However, it's not efficient, too long, and does not consider more words inside an input: https://code.sololearn.com/cTH1bcO6lrxd/?ref=app Does anyone has any better solutions with some explanations? If so, I'll be thankful. Thanks

26th Dec 2022, 6:54 PM
Lamron
Lamron - avatar
3 ответов
+ 3
the if len(y) == [number here] is not needed and your whole code can be shorten to this using foreach loop food = { "Mango" : 9, "Lettuce" : 5, "Carrot" : 4, "Cheeseburger" : 0} x = input() y = x.split(" ") s = 0 for v in y: s += food.get(v, 0) if(s >= 10): print("Come on Down!") else: print("Time to wait")
26th Dec 2022, 7:03 PM
Vanessa Nilsson
+ 2
It is np!
26th Dec 2022, 7:06 PM
Vanessa Nilsson
+ 1
I thought about loops few mins ago. But thanks for the explanation and provision of code. Appreciate it
26th Dec 2022, 7:05 PM
Lamron
Lamron - avatar