- 1

Here is my first traffic lights code. Please help me out and tell me why is it not working? 🙏

color=('red', 'yellow', 'green') if color=='red': print (stop) elif color=='yellow': print (ready) elif color =='green': print (go) (input('color:'))

3rd May 2020, 1:28 PM
Kashif Ali
Kashif Ali - avatar
4 Antworten
+ 6
You need to edit it . color=input("color: ") if color=="red": print("stop") elif color=="yellow": print("ready") elif color=="green": print("go")
3rd May 2020, 1:47 PM
Ayush Kumar
Ayush Kumar - avatar
+ 6
Because you input a value but you are not storing it in a variable. You need to move the last line to the beginning of the code and also remove the tuple called 'color'. Also, you need to write the words 'ready', 'go' and 'stop' in the quotes, because without them python tries to output variables with these names, which, however, do not exist. So, the working code looks like this: color = input('color: ') if color=='red': print ('stop') elif color=='yellow': print ('ready') elif color =='green': print ('go')
3rd May 2020, 2:02 PM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 2
Thanks guys, it works perfectly
3rd May 2020, 3:00 PM
Kashif Ali
Kashif Ali - avatar
0
And what if we want to create a loop after every 5min
4th May 2020, 6:46 AM
Kashif Ali
Kashif Ali - avatar