如何获取多个输入Python [英] How to get multiple inputs Python

查看:194
本文介绍了如何获取多个输入Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Python编写程序,我想执行以下操作: 我要求写一些信息

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())

现在,给定我分配给该输入的数字"N",然后我将获得N行以请求新输入.例如,如果我给数字3作为输入,我希望程序要求输入3个新的输入并将它们分配给某些字母:

Now, given the number 'N' I assign to this input, I would to then get N lines asking for new input. For example, if I give as input the number 3, I would like the program to ask for 3 new inputs and assign them to certain letters:

x = int(input())
3

然后

a = input()
b = input()
c = input()

关于如何执行此操作的任何想法?

Any idea on how to do this?

推荐答案

将它们分配给输入量未知的某些变量不是您想要的.您可以做的是输入以下内容列出一个列表:

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

现在您可以索引input_list以获得第n个输入:

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

print input_list[0]

这将返回第一个输入,因为Python中的索引从0开始

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

这篇关于如何获取多个输入Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆