Python Forum
Looping over amount of attempts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping over amount of attempts
#1
Hey so my code is about a username and password system. My issue is that after the user fails to input the correct details (from Intro) more than once it appears with the same message. What should be happening is that when attempt = 2, it should say you have 1 more attempt. If they entered the wrong details again, the message you have entered 3 times and you are now locked out, contact the network office. This is part is in Username_Submit(name). Doesn't appear with an actual error, I think it justs loops over.

import time


def intro(): #Username and Password is displayed
    print("Hello, your username is: Greg232 ")
    time.sleep(1)
    print("Your password is: userword657")
    Username_verify()

def Username_verify():
    name = Username_Name()
    proceed = Username_Submit(name)#Prints the credientals the user has put in
    print(proceed)


def Username_Name(): #User must input the correct username and password given to them
    name=list()
    username = input('Username: ')   
    double_check = input('Are you sure? ')
    if double_check != 'yes':
          Username_Name()     #If they say anything other than yes they will need to input their username again
    if double_check == 'yes':
            print('Proceed...')
            name.append(username)
            
    password = input("Password: ")
    double_check = input('Are you sure? ') 
    if double_check != 'yes':
        return double_check
        name.remove(Username_Name())
    if double_check == 'yes':
        name.append(password) #If the user says yes then Username_Submit(name) will check they match with the
                              #correct credientials 
    if Username_Submit(name) != 'Greg232' and  'userword657':
        name.remove(Username_Name())
        

    return name


def Username_Submit(name):
    attempt = 1 
    print(name[0], name[1])

    Submit = input("Submit?") #Double checks that the user is ok with what they entered
    if Submit == 'yes':
         if name[0] == 'Greg232' and name[1] == 'userword657':
             print("You may enter the system...")#User inputs correct username and password 
         else:                                   #therefore they can enter the system
             while name[0] != 'Greg232' and name[1] != 'userword657' and attempt == 1:
                 attempt = attempt + 1 #Username or/and password is not correct, they have 2 more attempts
                 print("Your username or password is wrong.")
                 print("You have 2 more attempts left. ")
                 Username_Name()
                 print(name[0], name[1])
                 Submit = input("Submit?")
                 if Submit == 'yes':
                     if name[0] == "Greg232" and name[1] == "userword657" and attempt == 1:
                      print("You may enter the system...")#User can retry typing in the correct details 
                      
                     
                     elif name[0] != 'Greg232' and name[1] != 'userword657' and attempt == 2:
                         attempt = attempt + 1
                         print("You have 1 more attempt left.")
                         Username_Name()    #Everytime the user inputs the wrong log-in details,
                                        #a message will appear with the amount of attempts remaining
                     elif name[0] != 'Greg232' and name[1] != 'userword657' and attempt == 3:
                         print("You have entered 3 attempts and you are now locked out,")
                         print("contact the network office.")
                         
    else:
         Username_Name() #If user does not say yes they must re-enter their details 
         



intro()
Reply


Messages In This Thread
Looping over amount of attempts - by Beatenberg - Oct-15-2017, 11:08 PM
RE: Looping over amount of attempts - by gruntfutuk - Oct-16-2017, 12:24 PM
RE: Looping over amount of attempts - by Beatenberg - Oct-17-2017, 03:10 AM
RE: Looping over amount of attempts - by gruntfutuk - Oct-17-2017, 07:34 AM
RE: Looping over amount of attempts - by Beatenberg - Oct-17-2017, 07:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print the frequency of each coin for the combinations that sum to the amount N Pranav 3 2,566 May-19-2020, 06:16 AM
Last Post: Pranav
  Unexpected change to a list in a small amount of self-contained code Johno 5 2,896 Mar-15-2020, 05:06 PM
Last Post: jefsummers
  Program that displays the number with the greatest amount of factors ilusmd 3 2,843 Nov-01-2018, 08:28 PM
Last Post: ichabod801
  Guessing Game "limit 4 attempts" help rprollin 3 19,807 Jun-23-2018, 04:37 PM
Last Post: ljmetzger

Forum Jump:

User Panel Messages

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