class PlayerAttributes:
inventory = []
def __init__(self, name, inventory):
self.name = name
self.inventory = inventory # LIST
class Item:
def __init__(self, item_name, damage):
self.item_name = item_name
self.damage = damage
class Weapons(Item):
weapon_1 = Item("Me Sword", 100)
Player_1 = PlayerAttributes("Bob", [])
def get_name():
Player_1.name = input("Enter name here: ").capitalize()
commands()
def stats():
print("Name = " + str(Player_1.name), "\n",
"Inventory: ")
for x in Player_1.inventory:
print(str(x.item_name))
def commands():
prompt = None
prompt_choices = {"stats", "quit", "give"}
while prompt not in prompt_choices:
prompt = input("Enter Command: ").lower()
if prompt == "stats":
stats()
commands()
elif prompt == "quit":
quit()
elif prompt == "give":
Player_1.inventory.append(Weapons.weapon_1)
commands()
get_name()问题
--我目前正在通过调用if语句中的“命令()”返回while循环,但是被告知这是一个递归,它是不必要的,而且它具有扩展调用堆栈的副作用.
问题
,我该怎么做呢??
额外
如何扩展调用堆栈?
https://stackoverflow.com/questions/73094673
复制相似问题