-1

I want to use a while loop in this program instead of a for loop, but I don't know how and where to start? Any help would be apprecieated!

def password():
    guessCount = 0
    password = input("Anna please enter a password here\n:")
    guesser = input("Guesser please enter your name here\n:")
    print("Welcome",guesser,"to the Password Guessing Game.\nYou have 8 attempts to guess my password.\nGood Luck!")
    for count in range (8):
        passwordGuess = input("Guess the password\n:")
        if passwordGuess == password:
            guessCount = guessCount + 1
            print("Well Done!")
            print("It took you",guessCount,"attempt(s) to guess the password!")
            break
        else:
            guessCount = guessCount + 1
            print("Try again")
pts
  • 80,836
  • 20
  • 110
  • 183
  • 2
    Welcome to Stack Overflow :) What language is this? Please add a tag for that language. Also, why would you want to use a `while` loop here? – Alex Wayne Oct 09 '14 at 17:46
  • 2
    If you search for "user input while loop" you will find the general pattern for that. You might even find it in the language you're using. – Andrew Morton Oct 09 '14 at 17:48
  • I don't know why you would want to do this, but you could literally swap the word for with while and have a `count=0` before the loop and it will all work. – Spade Oct 09 '14 at 18:05
  • Remember always to search on Google before posting a question. If your question is of the variety "How do I generally use ?", then there are probably countless explanations online. – sgarza62 Oct 09 '14 at 18:17

1 Answers1

0

If you want to do something similar to a for loop you could write something like this.

x = 0
while x in range(8): #alternately while x<8:
    ...
    x +=1

this will do the same thing as for x in range(8).

ragingSloth
  • 1,094
  • 8
  • 22