【发布时间】:2022-11-25 04:43:53
【问题描述】:
我正在为一个简单的游戏制定解决方案,您可以选择最多 5 名玩家和最少 2 名玩家的数量。每个玩家都由他们的名字和姓氏标识。
max_players = int(input(" Insert the number of players there are there? : "))
while len(players_list) < max_players:
player1 = input(" What is your first and last name? : ")
players_list.append(players)
print("players so far : ")
player2 = input ("What is your first and last name? :")
players_list.append(players)
print("players so far : ")
print(players_lists)
该代码部分起作用。问题是,虽然我提到了玩家的最大数量,但你仍然可以使用大于 5 的数字。另外,当我插入玩家的名字时,它显示“玩家”没有定义? 预期的输出是
Hello how many players are in the game?
insert number between 2 and 5
Please insert your name
然后对其他玩家执行相同的命令。
【问题讨论】: