pythonlistfrozenset

Python: store userinput in list until quit


This is my current code:

    account_number = [" "]
uinput = int(input("Type some Bank account numbers. Type "quit" to stop: "))
while uinput != "quit":
    account_number.append(uinput)
else:
    print(Kontonummern, frozenset)

I want to store "uinput" in my list "account_number" until the user enters "quit". After that the list should turn into a frozenset and print it out.

As of now I can only type 1 account number and then the programm crashes.


Solution

  • Try this:

    account_number = [" "]
    uinput = input("Type some Bank account numbers. Type quit to stop: ")
    while uinput != "quit":
        account_number.append(int(uinput))
        uinput = input("Type some Bank account numbers. Type quit to stop: ")
    else:
        print(Kontonummern, frozenset(account_number))
    

    The problem was that you were never updating your uinput. And your input can be "quit" but you cast it to an int, which was also causing problems.