Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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 3.x 是否有一种方法可以多次从用户处获取输入,并在不丢失以前的打印输入点的情况下进行打印?python_Python 3.x_Matplotlib - Fatal编程技术网

Python 3.x 是否有一种方法可以多次从用户处获取输入,并在不丢失以前的打印输入点的情况下进行打印?python

Python 3.x 是否有一种方法可以多次从用户处获取输入,并在不丢失以前的打印输入点的情况下进行打印?python,python-3.x,matplotlib,Python 3.x,Matplotlib,例如,如果我们有: xs = [1, 2, 3, 4, 5, 6, 7, 8, 9] ys = [1, 2, 3, 4, 5, 6, 7, 8, 9] name = [a, b, c, d, e, f, g, h, i] while True: user_input = input('Enter name: ') for i, j, name in zip(xs, ys, name): if(user_input == name): ax.

例如,如果我们有:

xs = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ys = [1, 2, 3, 4, 5, 6, 7, 8, 9]
name = [a, b, c, d, e, f, g, h, i]
while True:
    user_input = input('Enter name: ')
    for i, j, name in zip(xs, ys, name):
        if(user_input == name):
            ax.scatter(i, j)
            plt.show()
基本上,这里用户输入一个名称,然后根据它的xs和ys坐标进行绘制。
如何使用户输入另一个名称时,它也会被打印,而不会丢失以前的名称打印?

您需要创建一个数据结构来保存以前的用户输入,可能一个列表很难从这里的最小细节中分辨出来。我将使用(默认)dict而不是3个单独的列表。查找速度要快得多,尤其是当用户很多时。此外,您还可以动态地向绘图添加子绘图,如下所述:。最后一件事,你应该考虑的是明确地投入您的输入到任何类型的关键是,以避免不必要的行为。