+ 9
Please what is wrong with this program? It keeps telling me that break is outside the loop. [solved]
16 Answers
+ 10
Have you tried indenting it?
+ 9
Yeah, I started testing more. I got output when I did this:
import random
Name = input ("What is your name?\n")
print("Good Luck!" + Name)
Words = ["Rainbow" ,"Computer" ,"science" ,"Programming" ,"Python","Mathematics" ,"Player" ,"Condition" ,"Reverse" ,"Water" ,"Board" ,"Geeks"]
Word = random.choice (Words)
print ("Guess the characters")
Guesses = ' '
Turns = 10
while Turns > 0:
failed = 0
for char in Word:
if char in Guesses:
print (char)
else:
print("_")
failed += 1
if failed == 0 :
print ("You win")
print ("The word is:",word)
break
Guess = print(input("guess a character"))
Guesses += Guess
if Guesses not in Word:
turns -= 1
print ("Wrong")
print ("You have" + Turns + "more guesses")
if Turns == 0:
print (" You loose!")
+ 9
The second version I posted here gave output. If you run it the error will no longer show, but i want to know if that's what you were trying to do
+ 8
Line 21
+ 8
See if that helps
+ 8
No worries. Is this any better?
+ 7
import random
Name = input ("What is your name?\n")
print("Good Luck!" + Name)
Words = ["Rainbow" ,"Computer" ,"science" ,"Programming" ,"Python","Mathematics" ,"Player" ,"Condition" ,"Reverse" ,"Water" ,"Board" ,"Geeks"]
Word = random.choice (Words)
print ("Guess the characters")
Guesses = ' '
Turns = 10
while Turns > 0:
failed = 0
for char in Word:
if char in Guesses:
print (char)
else:
print("_")
failed += 1
if failed == 0 :
print ("You win")
print ("The word is:",word)
break
Guess = print(input("guess a character"))
Guesses += Guess
if Guesses not in Word:
turns -= 1
print ("Wrong")
print ("You have" + Turns + "more guesses")
if Turns == 0:
print (" You loose!")
+ 4
Please where exactly? Shewe Uchi K
+ 3
Not to bother you but the break statement is not working. It just goes on and the words I guess are not even printed in the output
+ 3
Mike Hill you're supposed to guess but no worries I've already gotten the help I need.
+ 3
Thank you guys for your help
0
I am not entirely sure what the objective is here. Is this supposed to automatically finish with no opportunities to guess or are we supposed to be able to guess...