1

I have an issue with a random item drop system in my game.

Here is my code:

import random

#Potato heals +5
potato = "Potato"
apple = 1
apple_name = "apple"

#is_damage_2
rusted_sword = "Rusted shortsword"

#Worth $80 - 10 can make Goldblade
gold_ingot = "Gold ingot"

#Worth $120
sapphire = "Sapphire"

random_drop = [sapphire,potato,gold_ingot,rusted_sword]

inventory = [apple_name, apple,]

rand_item = random.choice(random_drop)

inventory += rand_item

print(inventory)

When it prints the inventory... the random item is added, but it's spelled out letter for letter like this: P, o, t, a, t, o.

I want it to be spelled out like: "Potato"

I've only been learning Python for a few weeks and am very confused. Any help would be greatly appreciated!

  • Justin

1 Answers1

3

Use the append() method, like this:

inventory.append(rand_item)

See these answers about what += does for iterables.

Python append() vs. + operator on lists, why do these give different results?

Why does += behave unexpectedly on lists?

swagrov
  • 1,510
  • 3
  • 22
  • 38