Python Argument Help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python Argument Help

I am trying to get my code to save two arguments instead of just one. Simply put, I made my code choose a random number. Based on the number generated, the player receives a different item. However, I'm trying to add weapons with different ammo counts into a broad (list?) basically: items = [] this list contains swords as well. So, how can I place items in there, that have a name and an ammo count?

16th Jan 2018, 4:06 PM
Stef
Stef - avatar
6 Answers
0
I want to be able to print the weapon's name and ammo count to create something like this.(the code doesn't compile correctly, however, this is the general idea https://code.sololearn.com/c64EnMckKUDs/?ref=app
18th Jan 2018, 3:10 PM
Stef
Stef - avatar
+ 1
use dictionary to contain key and value pair {'weapon':ammo}
16th Jan 2018, 5:06 PM
Pavan Kumar T S
Pavan Kumar T S - avatar
+ 1
as you asked you require a method to store name of weapon and ammo count so using dictionary instead of list will solve the problem eg:- {"swards":25}
16th Jan 2018, 5:30 PM
Pavan Kumar T S
Pavan Kumar T S - avatar
+ 1
you are already storing ammo in object why you need to store again https://code.sololearn.com/clFbR0Rj4z2y/?ref=app
18th Jan 2018, 1:39 PM
Pavan Kumar T S
Pavan Kumar T S - avatar
0
what do you mean? or what would that look like?
16th Jan 2018, 5:27 PM
Stef
Stef - avatar
0
this is the part of my code that I am testing. it is really messy, but how would I fix this with dictionaries? https://code.sololearn.com/c9DG07ezqdNw/?ref=app
16th Jan 2018, 5:46 PM
Stef
Stef - avatar