
October 4th, 2012, 04:39 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 9 m 9 sec
Reputation Power: 0
|
|
|
Conditional Statements
Hey! I'm trying to program a very simplistic hangman game, and in doing so, I have to break out of a while loop after so many right guesses or so many wrong guesses. The while loop ends if I have just one conditional statement, but when I include [conditional1 or conditional2] the loop continues infinitely. Is there any way I can remedy this? My code is posted below
Code:
import random
a=['hello', 'goodbye', 'hola', 'chao']
n=random.randrange(0, len(a))
guessRight=0
guessWrong=0
while guessWrong < 7 or guessRight < len(a[n]):
g=raw_input("Guess a letter: ")
if(g in a[n]):
guessRight+=1
print "Word contains " + str(gr)
else:
guessWrong+=1
print "Incorrect guess\n"
if(guessWrong==7):
print "You lost"
else:
print "You win"
Thanks,
mcdom34
|