+ 1

Python: Subtracting from definitions/lists?

In this code I am giving the user a few different guns. they encounter an enemy and are asked which gun they would like to use. this is where I get stuck. after they use the gun i try to subtract 1 from that specific gun's ammo count. (Which I don't know how to do...) And after that, I try to print out what weapon was used and what its ammo count is now at. I described it a little more in the code. Any help is appreciated!!!! :D https://code.sololearn.com/camY2OQRav8W/?ref=app

26th Jan 2018, 5:51 PM
Stef
Stef - avatar
2 Answers
+ 1
guns = {"pistol": 6, "sniper": 4, "rocket launcher": 2} print ("there is a monster in front of you!") print ("use a weapon to kill the enemy?") user_resp = raw_input("yes/no\n") if "yes" in user_resp: print ("which weapon would you like to use?") print (guns) user_resp = raw_input("") if user_resp in guns: print ("you shot your " + str(user_resp)) # update will not increment the value, instead try # guns.update({"user_resp": -1}) guns[user_resp] -= 1 #this line is where im trying to subtract one ammo #from the weapon the user chose. print ("your " +user_resp+ " now has " + str(guns[user_resp])) #im not sure how to write what weapon #the user chose. and how to write the subtracted ammo count.
26th Jan 2018, 9:50 PM
richard
0
looks good! thanks!! :)
27th Jan 2018, 12:51 AM
Stef
Stef - avatar