0

On the elif section question.

On the elif playground there are 3 boxes for 3 different colors. Box 1 is red Box 2 is green Box 3 is black You're supposed to write elif statements to output the number box it goes into. I've tried this several different times using color variables, strings, and I can't get it. What am I doing wrong? A code I've tried...---- color = input() if color == 2: print("2") elif color == 3: print("3") elif color == 1: print("1") else: print("this message")

30th Aug 2020, 2:02 AM
Parallel Visions
Parallel Visions - avatar
4 Réponses
+ 4
You're comparing a string to an integer, I am assuming your input is an integer... Try this color=int(input()) Or if color=="2": Either option should make your code work. You need to compare like objects... apples to apples, orange to oranges. Hope this helps
30th Aug 2020, 2:08 AM
Steven M
Steven M - avatar
+ 2
Amazing. I figured it out. "Comparing like objects" made it click for me, thanks! Code spoiler below vvvv #this is the answer. color = input() if color == 'red': print(1) elif color == 'green': print(2) elif color == 'black': print(3)
30th Aug 2020, 2:22 AM
Parallel Visions
Parallel Visions - avatar
+ 1
🎉🎉🎉 🥇 🎉🎉🎉 NICE!
30th Aug 2020, 2:29 AM
Steven M
Steven M - avatar
0
Use colours to equate or use the int no mistakes no more
30th Aug 2020, 6:07 PM
XYNCSTEP
XYNCSTEP - avatar