在用户输入列表中满足条件时停止while循环

时间:2018-06-03 08:22:13

标签: python python-3.x while-loop

我是否正在尝试创建一个寄存器,该寄存器将用户输入附加到列表中,中断并返回到用户“输入数据”的提示,但仅在输入字符串“done”时停止。

userinput = input("Please Input price: ")
price = [userinput]

    while True:
       if price.append(userinput) is True:
        print(price)
       if price.append("done") is True:
        break

    print(price)

1 个答案:

答案 0 :(得分:0)

userinput = input("Please Input price: ")
price = []

while userinput != "done":
    price.append(userinput)
    print(price)  # This appears to serve as debugging only, you will see the whole list as it is grown
    userinput = input("Please Input price: ")

print(price)