Python While循环函数
我想设置一个while循环函数或任何其他可能性,以便使用once str(input()),而不是重复操作10次Python While循环函数,python,loops,while-loop,Python,Loops,While Loop,我想设置一个while循环函数或任何其他可能性,以便使用once 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: [
# 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)
将输入替换为回路:
# 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()) for _ in range(10)],
}
).set_index('Numéro')
df.append(df_1)
df = pd.concat(df, axis=1)
print(df)
我还建议重命名
Numéro
,使用变音符号可能会导致未来不同系统出现问题。将输入替换为循环:
# 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()) for _ in range(10)],
}
).set_index('Numéro')
df.append(df_1)
df = pd.concat(df, axis=1)
print(df)
我还建议重命名
Numéro
,使用变音符号可能会导致将来不同系统出现问题。您可以用
for i in range(0,10):
player.append(str(input()))
您可以将列表替换为
for i in range(0,10):
player.append(str(input()))
将列表替换为
[str(input())表示范围内(10)]
您也可以使用列表(范围(1,11))
将列表替换为[str(input())表示范围内(10)]
您还可以使用列表(范围(1,11))