Python Forum
Keeps looping even after correct answer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keeps looping even after correct answer
#1
I cant get this to stop looping even after correct answer. Any help would be greatly appreciated.
# Administrator accounts list
adminList = [
    {
        "username": "DaBigBoss",
        "password": "DaBest"
    },
    {
        "username": "root",
        "password": "toor"
    }
]

# Build your login functions below
def getCreds():
    username = input("What is your username? ")
    password = input("What is your password? ")

    return {"username": username, "password": password}

def checkLogin(adminList, user_info):
    if user_info in adminList:
        getCreds = True
        print("YOU HAVE LOGGED IN!")
    else:
        getCreds = False
        print("----------")
        print("Login Failed")
        print("----------")
        retry = getCreds
        return

while True:
    user_info = getCreds()
    is_admin = checkLogin(adminList, user_info)
    print("----------")
    if is_admin:
        print("YOU HAVE LOGGED IN!")
        break
Reply
#2
your checkLogin function will ALWAYS return None.
None is evaluated as False (on line 36) so you never break
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you for your help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Looping a question until correct feedback is given TylerTrunzo 9 1,726 Oct-31-2022, 12:19 PM
Last Post: rob101
  why don't i get the answer i want CompleteNewb 12 3,296 Sep-04-2021, 03:59 PM
Last Post: CompleteNewb
  I am getting the wrong answer, and not sure why riskeay 3 2,003 Nov-05-2020, 08:24 PM
Last Post: deanhystad
  Make the answer of input int and str enderfran2006 2 1,970 Oct-12-2020, 09:44 AM
Last Post: DeaD_EyE
  I don't think my program is producing the correct answer emmapaw24 1 1,677 Mar-31-2020, 01:13 AM
Last Post: stullis
  I'm getting a wrong answer don't know where the bug is 357mag 4 2,763 Jul-07-2019, 11:21 PM
Last Post: DeaD_EyE
  How to answer subprocess prompt Monty 8 17,250 Feb-14-2018, 09:59 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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