Ad

Stopping A While Loop When A Condition Is Met In A Userinput List

- 1 answer

Please I'm trying to create a register that appends to a list the user input, breaks and returns to the prompt for user to "input data" but only stops when a string "done" is inputed.

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

Answer

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)
Ad
source: stackoverflow.com
Ad