【发布时间】:2021-01-14 22:29:48
【问题描述】:
我想设置一个 while 循环函数或任何其他可能性,以便使用一次 str(input()) 而不要重复操作 10 次。
# Name of the player for the game
colonne= ['player_name']
df = []
for player in colonne:
df_1 = pd.DataFrame(
{
'Numéro': [1,2,3,4,5,6,7,8,9,10],
player: [
str(input()),
str(input()),
str(input()),
str(input()),
str(input()),
str(input()),
str(input()),
str(input()),
str(input()),
str(input()),
],
}
).set_index('Numéro')
df.append(df_1)
df = pd.concat(df, axis=1)
print(df)
【问题讨论】:
-
将列表替换为
[str(input()) for _ in range(10)] -
您也可以使用
list(range(1,11))创建“Numero”列表
标签: python loops while-loop