我正在尝试制作一个系统,在这个系统中,用户可以在游戏中从1到3选择要面对多少个机器人,但我很难弄清楚如何使用给定的值作为名称自动创建机器人。你知道吗
while True:
try:
Player_Count = int(input("How many bots do you want to play against from 1 - 3?"))
except ValueError:
print("That's not a number! Try again!")
else:
if 1 <= Player_Count <= 3:
break
else:
print("Out of Range! Try Again")
这部分工作正常,但我不知道如何使用Player_Count
变量作为列表的名称(bot的数据将存储在这些列表中)
我做过,但我想这是一个非常糟糕的方法:
for bot in range(Player_Count):
if bot == 0:
bot1 = []
if bot == 1:
bot2 = []
if bot == 2:
bot3 = []
任何帮助都将不胜感激!你知道吗
制作一个列表,每个机器人都有自己的内部列表,机器人的总数由输入的
player_count
决定:您可以通过
len(bots)
找到bot的数量,并索引到bots
以找到每个单独的框。你知道吗相关问题 更多 >
编程相关推荐