Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading