我的游戲中的隨機(jī)物品掉落系統(tǒng)有問題。這是我的代碼:import random#Potato heals +5potato = "Potato"apple = 1apple_name = "apple"#is_damage_2rusted_sword = "Rusted shortsword"#Worth $80 - 10 can make Goldbladegold_ingot = "Gold ingot"#Worth $120sapphire = "Sapphire"random_drop = [sapphire,potato,gold_ingot,rusted_sword]inventory = [apple_name, apple,]rand_item = random.choice(random_drop)inventory += rand_itemprint(inventory)當(dāng)它打印庫存時(shí)...隨機(jī)項(xiàng)目被添加,但它是這樣拼寫一個(gè)字母的:P,o,t,a,t,o。我希望它拼寫為:“土豆”我只學(xué)了幾周 Python,很困惑。任何幫助將不勝感激!賈斯汀
1 回答

隔江千里
TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
使用 append() 方法,如下所示:
inventory.append(rand_item)
請參閱這些關(guān)于+=
可迭代對象的作用的答案。
添加回答
舉報(bào)
0/150
提交
取消