0

Red and green don't work but black does can anyone help me fix please?

If you enter red or green it shows the output box number correct but also shows unknown. Don't know why and all other colors work correctly as showing just unknown. Please assist if you can. https://code.sololearn.com/c48uGY6bZ22x/?ref=app

12th May 2023, 2:05 PM
Nicholas Mcintyre
Nicholas Mcintyre - avatar
4 ответов
+ 8
Corrected code: color = input() if color=="red": print("box #1") elif color=="green": print("box #2") elif color=="black": print("box #3") else: print("unknown") - no need for parenteses around input - if you want only a single condition to evaluate, use "elif" in the middle - use consistent indentation (4 characters everywhere is usual)
12th May 2023, 2:19 PM
Tibor Santa
Tibor Santa - avatar
+ 3
Hello tibor Santa thank you very much for the help. And you mean four spaces for indentation correct?
12th May 2023, 2:33 PM
Nicholas Mcintyre
Nicholas Mcintyre - avatar
+ 2
Yes, 4 spaces.
12th May 2023, 2:36 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa is right! But you can use dictionary here instead using too many if-else condition. color = input() box = { "red":"box #1", "green":"box #2", "black":"box #3" } print(box.get(color, "unknown"))
14th May 2023, 4:54 AM
Fꫀⲅძ᥆͟ᥙ᥉᯽
Fꫀⲅძ᥆͟ᥙ᥉᯽ - avatar