Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
String 循环Python(PyCharm)的用户输入_String_For Loop_Pycharm - Fatal编程技术网

String 循环Python(PyCharm)的用户输入

String 循环Python(PyCharm)的用户输入,string,for-loop,pycharm,String,For Loop,Pycharm,我正试图用for循环编写一个程序。我想问用户他们想列出多少字符串。然后,根据他们输入的数字,在for循环中使用它,要求他们一次一行输入多个字符串,以填充列表中的项目 输出的例子是 How many items do you want in your list? 3 string 1: bread string 2: toothpaste string 3: eggs [‘bread’, ‘toothpaste’, ‘eggs’] 我正在使用Pycharm,不知道从哪里开始。 第一次使用

我正试图用for循环编写一个程序。我想问用户他们想列出多少字符串。然后,根据他们输入的数字,在for循环中使用它,要求他们一次一行输入多个字符串,以填充列表中的项目

输出的例子是

How many items do you want in your list? 3 
string 1: bread 
string 2: toothpaste 
string 3: eggs
[‘bread’, ‘toothpaste’, ‘eggs’] 
我正在使用Pycharm,不知道从哪里开始。 第一次使用for循环。

尝试以下方法:

try:
    ite = int(raw_input("How many items do you want in your list? "))
    stringList = []
    for i in range(ite):
        stringList.append(raw_input("string {0}:".format(i)))
    print(stringList)
except:
    print("Not a Number")

没问题@user2388433。如果有帮助的话,欢迎接受我的回答P:)像一个魔咒一样令人惊叹。我确实编辑了一个部分,该部分允许程序从1开始输出,而不是从0开始。再次感谢