Please what is wrong with this program? It keeps telling me that break is outside the loop. [solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

Please what is wrong with this program? It keeps telling me that break is outside the loop. [solved]

https://code.sololearn.com/cnYXMNxLJnwB/?ref=app

1st Jul 2020, 10:08 PM
Chimamanda
Chimamanda - avatar
13 Answers
+ 10
Have you tried indenting it?
1st Jul 2020, 10:16 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
+ 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!")
1st Jul 2020, 10:34 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
+ 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
1st Jul 2020, 10:44 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
+ 8
Line 21
1st Jul 2020, 10:28 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
+ 8
See if that helps
1st Jul 2020, 10:29 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
1st Jul 2020, 11:04 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
+ 8
No worries. Is this any better?
1st Jul 2020, 11:05 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
+ 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!")
1st Jul 2020, 10:29 PM
Fenix B Monsanto
Fenix B Monsanto - avatar
+ 4
Please where exactly? Shewe Uchi K
1st Jul 2020, 10:22 PM
Chimamanda
Chimamanda - avatar
+ 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
1st Jul 2020, 10:47 PM
Chimamanda
Chimamanda - avatar
+ 3
Mike Hill you're supposed to guess but no worries I've already gotten the help I need.
5th Jul 2020, 12:34 PM
Chimamanda
Chimamanda - avatar
+ 3
Thank you guys for your help
5th Jul 2020, 12:34 PM
Chimamanda
Chimamanda - avatar
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...
3rd Jul 2020, 4:40 PM
Mike Hill
Mike Hill - avatar