Please what is wrong with this program? It keeps telling me that break is outside the loop | SoloLearn: Learn to code for FREE!

+4

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

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

7/1/2020 10:08:28 PM

Amanda Unachukwu

16 Answers

New Answer

+10

Have you tried indenting it?

+8

+8

See if that helps

+8

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!")

+8

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

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

+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!")

+2

Please where exactly? Shewe Uchi K

+1

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

+1

ensuwnsiwnn

+1

Mike Hill you're supposed to guess but no worries I've already gotten the help I need.

+1

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...