Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop not closing
#5
Look how often you ask for input. Why make a variable just to break out of the loop?
def main():
    print("1) Create a new user ID")
    print("2) Change a password")
    print("3) Display all user ID's")
    print("4) Quit")
    print()
    while True:
        choice = input("Please enter your selection:")  # Why make it an integer???
        if choice == '1':
            data = getdata()
            newid = createid(data)
            password = createpassword()
            newrecord = newid + "," + password
            data.append(newrecord)
            with open("ID+Passwords.csv","w") as file # Closes file when done
                for row in data:
                    file.write(newrecord)
        elif choice == '2':
            data = getdata()
            changepassword(createid(data), data)
        elif choice == '3':
            display(getdata())
        elif choice == '4':
            break
        else:
            print("Invalid choice.")
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 2,912 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