gpt4 book ai didi

python - 回合制游戏的菜单

转载 作者:行者123 更新时间:2023-12-05 07:03:03 30 4
gpt4 key购买 nike

我们的老师给我们布置了一项任务,让我们做一款回合制游戏。

这只包括 name.strip() 但这不会提示玩家输入唯一的名字:

def start():

print("\nNew game started...Setting up Player 1's team...\n")

for total_characters in range (1,4):
name = input('Enter a unique name for unit #'+str(total_characters)+'==> ')
if not name.strip():
print('Cant be blank name,please provide a unique name')
return start()
else:
role_selection()

def role_selection():
for total_characters in range (1):
role = input('Select unit #'+str(total_characters)+' type: (W)arrior, (T)anker, or Wi(Z)ard ==> ')
total_characters+=1
if role.upper() == 'W':
pass
elif role.upper() == 'T':
pass
elif role.upper() == 'Z':
pass
else:
print("I don't understand what are you typing.")
return role_selection()

最佳答案

有些事情没有意义:

  • 你有两次完全相同的功能:

    def set_up(team_size)

    def set_up(名称)

  • 你正在做:

    for total_units in range(team_size):
[...]

invalid = True

[...]

while invalid: # Infinite loop
set_up() # What's this function ?

从上面代码的注释中可以看出,您从未将invalid设置为False,导致死循环。

注意:我的建议是,在继续编写复杂项目之前,您应该查看一些 python 教程,因为您的家庭作业并不那么容易。

编辑:

根据您发布的新代码,您可以执行如下操作:

def new_game():
names = []
for unit_id in range(1,4):
print(f'Enter a unique name for unit #{unit_id} ->')
empty = True
while empty:
name = input('>')
if name == "":
continue
empty = False
if name in names:
print('Unit name must be unique.')
else:
print('Name looks good!')
names.append(name)

python menu

关于python - 回合制游戏的菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63372371/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com