Wednesday, 25 September 2013

python breaking if statement inside for loop

python breaking if statement inside for loop

I want the if-statement to break if the condition is met, because
currently if it isn't broken early then I get some mishaps in my code.
The problem is, I am not sure where to put the break. When I put it where
it is shown here I get "Unexpected indent", but when I put it back a level
I get an error with the else-statement saying "Invalid Syntax".
So I am not sure what to do. Any help would be appreciated.
def pTurn(CampLoc, AICampLoc, score, yourHits, cHits):
if yourHits < 5:
hGuess = int(raw_input("Enter a co-ordinate to air-strike: "))
print "Air-striking co-ordinate: %d" % hGuess
for cSpot in AICampLoc:
if hGuess == cSpot:
yConfirMsg = "Kill confirmed!!"
yourHits += 1
score += 100
AICampLoc.remove(hGuess)
break
else:
yConfirMsg= "No casualties"
score = score
yourHits = yourHits

No comments:

Post a Comment