Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I end my while loop
#3
(Jan-22-2021, 02:08 PM)buran Wrote: input will return str, so you need to compare choice with '2' or convert the user input to int and then you can compare with 2.
Then to end the loop choice must become 'exit'
also, I must comment on excessive use of brackets - no need of brackets in cases like ("enter")

So your solution did work but when I input an incorrect value but after that, I input the correct value '2' it still says error.
#getpass will hide what the person is typing during the password
import getpass

def new_entry():
  #input the username and password and the website
  Website = input("Enter the website: ")
  Username = getpass.getuser()
  Password = getpass.getpass()

#Menu to choose if you want to add, see or remove
print("  *************************")
print(" /$$   /$$ /$$$$$$ /$$$$$$$ \n| $$  | $$|_  $$_/| $$__  $$\n| $$  | $$  | $$  | $$  \ $$\n| $$$$$$$$  | $$  | $$  | $$\n| $$__  $$  | $$  | $$  | $$\n| $$  | $$  | $$  | $$  | $$\n| $$  | $$ /$$$$$$| $$$$$$$/\n|__/  |__/|______/|_______/ ")
print("**************************")
print ("1. See the list\n2. Add new entry")

choice = int(input(""))
c = "enter"

while c != ("exit"):
  if (choice) == (2):
    new_entry()
    c = ("enter")
    #if you select option 2 it will call the new_entry code
  else:
    choice = input("ERROR:\nInvalid input: Please type agian\n")

#Store this somewhere
Feel free to try it out and thanks
Reply


Messages In This Thread
How do I end my while loop - by TechNitium - Jan-22-2021, 01:56 PM
RE: How do I end my while loop - by buran - Jan-22-2021, 02:08 PM
RE: How do I end my while loop - by TechNitium - Jan-22-2021, 02:33 PM
RE: How do I end my while loop - by buran - Jan-22-2021, 03:06 PM
RE: How do I end my while loop - by BashBedlam - Jan-22-2021, 04:49 PM
RE: How do I end my while loop - by TechNitium - Jan-22-2021, 05:07 PM

Forum Jump:

User Panel Messages

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