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()
PROBLEM
我现在通过在if语句中调用"commands()"返回"prompt"的while循环,但被告知这是一个递归,没有必要,而且它有一个增加调用堆栈的副作用...
QUESTION
我应该怎么做??
Extra
它将如何增加调用堆栈?