Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 如何存储问题并生成&;列表_Python_List_While Loop_Append - Fatal编程技术网

Python 如何存储问题并生成&;列表

Python 如何存储问题并生成&;列表,python,list,while-loop,append,Python,List,While Loop,Append,我试图编写一个代码,询问用户是存储/添加问题还是列出问题。如果用户选择add,他们会编写并存储问题。然后,当他们选择列表时,将显示问题。我的问题是,当我在先前添加的问题中添加一个问题,然后选择列出问题时,它不会同时打印两个问题,只打印最新添加的问题 为什么会这样?这是中断函数终止循环的原因吗 谢谢 如果选择=='a' l=[] while True: name =(input('enter')) l.append (name)

我试图编写一个代码,询问用户是存储/添加问题还是列出问题。如果用户选择add,他们会编写并存储问题。然后,当他们选择列表时,将显示问题。我的问题是,当我在先前添加的问题中添加一个问题,然后选择列出问题时,它不会同时打印两个问题,只打印最新添加的问题

为什么会这样?这是中断函数终止循环的原因吗

谢谢

如果选择=='a'

l=[]

    while True:

        name =(input('enter'))


        l.append (name)

                break
if choice == 'l':
    print (l)
尝试这样做:

while raw_input("Do you have more questions?") is not "No":
    list.append(raw_input("Enter your next question"))

..continue the program

也许,也许不是。你的密码在哪里?哈哈知道我漏掉了什么!!除非您遗漏了一些代码行,否则只需添加一个问题就可以了。如果您确实多次运行代码来添加多个问题,那么每次运行代码时,列表都会被重置:pyea我想就是这样!如何使其不重置:/n不重置列表:P只需检查它是否存在,如果存在,则不执行任何操作:)