+ 1

[SOLVED] Python: How can I make this work?

The problem is on line 3 of my code. I'm trying to get input from the user, and have my code check if that input is in the dictionary guns. from there I just want my code to print the user_resp. I'm just trying to get the mechanic down so I can use this technique in my other code. Any help is appreciated :D guns = ["pistol", "sniper", "rocket launcher"] user_resp = raw_input("") if user_resp == str in guns: print user_resp

22nd Jan 2018, 5:27 PM
Stef
Stef - avatar
4 Answers
+ 7
Sololearn uses Python3 interpreter, while your code is clearly written in Python2. Also, the syntax is even easier than you think ;) Your code, in order to work here should go like: guns = ["pistol", "sniper", "rocket launcher"] user_resp = input() if user_resp in guns: print(user_resp)
22nd Jan 2018, 8:55 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 2
thank you all! :)
23rd Jan 2018, 3:27 PM
Stef
Stef - avatar
+ 1
use if user_resp in guns:
22nd Jan 2018, 5:29 PM
michal
0
try this if user_resp in guns:
22nd Jan 2018, 5:29 PM
Jeremy
Jeremy - avatar