- 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:'))
4 Réponses
+ 6
You need to edit it .
color=input("color: ")
if color=="red":
print("stop")
elif color=="yellow":
print("ready")
elif color=="green":
print("go")
+ 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')
+ 2
Thanks guys, it works perfectly
0
And what if we want to create a loop after every 5min