Jul-01-2019, 07:52 AM
Hi Guys,
I am new to python and have very basic knowledge on python. I have written a small program below which gives user 3 chances for writing correct user name and 3 chances for correct password. But the user should be able to proceed further in giving password only if his user name is correct else user should be asked to leave out. Also if the user does not enter incorrect password for more 3 times he should be asked to leave out. Also if some one can help me how to post the code as my indentation are not appearing in below code Below is my code:
[username = "John"
password = "John123"
attempt = 0
attempt1 = 0
while attempt <4:
u = input ("Please enter the username : ")
if u == username:
print ("Correct username")
p = input ("Please enter the password : ")
if p == password:
print("Access Granted")
else:
print ("incorrect password")
if attempt1 == 4:
print ("Too many attemps, Bye")
else:
input ("try again :")
attempt1 = (attempt1 + 1)
else:
print ("incorrect username.")
if attempt ==4:
print ("To many attempts, better luck next time")
else:
input ("Please try again: ")
attempt = (attempt + 1)
input ("Please enter to exit")
]
When i am executing the code and giving incorrect username, the chances i am getting is only 2 and not three.
I am new to python and have very basic knowledge on python. I have written a small program below which gives user 3 chances for writing correct user name and 3 chances for correct password. But the user should be able to proceed further in giving password only if his user name is correct else user should be asked to leave out. Also if the user does not enter incorrect password for more 3 times he should be asked to leave out. Also if some one can help me how to post the code as my indentation are not appearing in below code Below is my code:
[username = "John"
password = "John123"
attempt = 0
attempt1 = 0
while attempt <4:
u = input ("Please enter the username : ")
if u == username:
print ("Correct username")
p = input ("Please enter the password : ")
if p == password:
print("Access Granted")
else:
print ("incorrect password")
if attempt1 == 4:
print ("Too many attemps, Bye")
else:
input ("try again :")
attempt1 = (attempt1 + 1)
else:
print ("incorrect username.")
if attempt ==4:
print ("To many attempts, better luck next time")
else:
input ("Please try again: ")
attempt = (attempt + 1)
input ("Please enter to exit")
]
When i am executing the code and giving incorrect username, the chances i am getting is only 2 and not three.