954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

need help stopping program after 3rd iteration

The program is suppose to create and account but if the passwords do not match after the 3rd iteration it's suppose to output that its been too many tries and end the program... I can't seem to figure this out any help would be greatly appreciated.

while 3:
    print ("Welcome to yor account creation")
    name =input('Enter your name: ')
    pasw =input('Enter your password: ')
    paswr =input('Re-enter your password: ')
    if pasw == paswr:
            print ("Your account has been created")
            break;
    if pasw != paswr:
        print ("Please re-enter information")
    if while <=3:
              print ("Too many incorrect tries, your account has not been created")
manofhouse
Newbie Poster
22 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

You need to set a variable for your while loop and change the bottom if statement. You then need to count to the variable each iteration. Also, you should take the name input and first print statement out of the loop so not to have it repeat each time.

print ("Welcome to yor account creation")
name =input('Enter your name: ')
    
n = 0     #add a variable set to 0
while n != 3:     #include variable in while statement 
	pasw =input('Enter your password: ')
	paswr =input('Re-enter your password: ')
	if pasw == paswr:
		print ("Your account has been created")
		break
	if pasw != paswr:
		print ("Please re-enter information")
		n += 1     #add 1 each iteration
	if n == 3:      #if 3 iterations run print and break
		print ("Too many incorrect tries, your account has not been created")
		break
joeywheels
Newbie Poster
18 posts since Feb 2011
Reputation Points: 13
Solved Threads: 0
 

Ahh I see... thank you so much!!!!

manofhouse
Newbie Poster
22 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

No problem. I'm a newbie too. People here are great so don't feel uncomfortable posting. These guys are a wealth of knowledge and willing help!

joeywheels
Newbie Poster
18 posts since Feb 2011
Reputation Points: 13
Solved Threads: 0
 

yea my prof made us switch over to python for this project idk why.. but I definitely won't. thanks again!

manofhouse
Newbie Poster
22 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: