How to get multiple inputs Python

前端 未结 2 395
忘掉有多难
忘掉有多难 2021-01-16 21:43

I\'m writing a program in Python where I would like to do the following: I ask for a certain input by writing

x = int(input())

Now, given t

2条回答
  •  我在风中等你
    2021-01-16 22:20

    Assigning them to certain variables with an unknown amount of inputs is not something you want. What you can do is make a list with the inputs:

    x = int(input()) # the amount of numbers
    input_list = []
    for i in range(x):
        input_list.append(input())
    print input_list
    

    Now you can index the input_list to get the n-th input:

    print input_list[0]
    

    This will return the first input as the indexing in Python starts from 0

提交回复
热议问题