Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python While循环函数_Python_Loops_While Loop - Fatal编程技术网

Python While循环函数

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: [

我想设置一个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: [
                 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))