Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop not closing
#1
I'm using a code with a while loop:

def main():
    print("1) Create a new user ID") # prints this menu
    print("2) Change a password")
    print("3) Display all user ID's")
    print("4) Quit")
    print()
    choice = int(input("Please enter your selection:")) # asks user for their selection
    try_again = True
    while try_again == True:
        if choice == 1:
            tmp = get_data() # gets tmp list from get_data
            New_ID = create_ID(tmp) # gets New_ID from create_ID
            password = create_password() # gets password 
            new_record = New_ID + "," + password # creates entry string
            tmp.append(new_record) # adds string to the end of tmp
            file = open("ID+Passwords.csv","w") # opens csv file in write mode
            for row in tmp:
                file.write(new_record) # writes every row of the list to the csv file
            file.close # closes the file and saves the changes 
            choice = int(input("Please enter your selection:")) # asks user for their selection
        elif choice == 2:
            tmp = get_data()
            New_ID = create_ID(tmp)
            change_password(New_ID,tmp)
            choice = int(input("Please enter your selection:")) # asks user for their selection
        elif choice == 3:
            tmp = get_data()
            display(tmp)
            choice = int(input("Please enter your selection:")) # asks user for their selection
        elif choice == 4:
            try_again == False
        else:
            choice = int(input("Incorrect choice please select a choice from the list:"))
However when I select option 4 the loop isn't closing properly, this is what my terminal looks like:

Please enter the new ID1
Please enter the new password:numbers0123
That is a strong password
Please enter your selection:4

Rather than going to the normal non-running terminal it just has a blank line underneath. Can anyone help with this?
Reply


Messages In This Thread
while loop not closing - by djwilson0495 - Aug-27-2020, 02:14 PM
RE: while loop not closing - by GOTO10 - Aug-27-2020, 02:29 PM
RE: while loop not closing - by Larz60+ - Aug-27-2020, 02:33 PM
RE: while loop not closing - by djwilson0495 - Aug-27-2020, 03:52 PM
RE: while loop not closing - by deanhystad - Aug-27-2020, 06:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Try-except in while loop: error with closing program Lupin_III 7 3,021 Jul-03-2020, 10:57 AM
Last Post: Lupin_III

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020