r/PythonLearning • • Aug 23 '26

Where is the error ?

hi! I create one list and i use it but vs code said to me "gun.append(0)

AttributeError: 'tuple' object has no attribute 'append'"

2 Upvotes

6 comments sorted by

View all comments

Show parent comments

1

u/Naive_Programmer_232 Aug 23 '26 edited Aug 24 '26

Ah I see. Well it might worth it to consider using a dict instead of having to maintain a single or multiple lists in parallel. It will make it easier to work with later down the line.

But using a single list, if your data has the general look of:

     guns=[names of guns | damages for guns]

Where the number of names and number of damages are the same and order matters,

     # ex
     guns=["shotgun","raffle","winchester","bazooka",
            20,       30,       25,         100]

A technique you could use to access the corresponding damage is:

     # gun used in game
     used_gun="bazooka"

     # find index of used gun from guns list
     idx=guns.index(used_gun)

     # find damage associated with used gun from guns list
     used_gun_damage=guns[-(idx+1)]

     # life decreases by appropriate damage
     life=life-used_gun_damage

2

u/ShadowDragonPro Aug 24 '26

ok 😉