这段代码的可能解决方案是什么[Python 3.x]

时间:2015-04-11 12:09:37

标签: python python-3.x

n_players = int(input('Welcome to the game, please tell me how many players will play: '))

print('Now tell me the names of the ', n_players, ' players')

for i in range(0, n_players):
    player_i = input('Enter the name of player',i)

问题出现在编译器告诉我存在错误的最后一行:/ 有什么想法吗?

3 个答案:

答案 0 :(得分:2)

你可以尝试这个来获取玩家名称:

player_names = []
for i in range(n_players):
    player_i = input('Enter the name of player {}: '.format(i + 1))
    player_names.append(player_i)

答案 1 :(得分:2)

input函数不能接收多个参数,需要进行插值:

player_list.append(input('Enter the name of player {}'.format(i + 1)))

答案 2 :(得分:0)

输入函数将一个字符串作为参数,而不是像可能需要许多项目的print。