+ 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 Unachukwu
Chimamanda Unachukwu - avatar
16 odpowiedzi
+ 10
Have you tried indenting it?
1st Jul 2020, 10:16 PM
Uri Easter
Uri Easter - 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
Uri Easter
Uri Easter - 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
Uri Easter
Uri Easter - avatar
+ 8
Line 21
1st Jul 2020, 10:28 PM
Uri Easter
Uri Easter - avatar
+ 8
See if that helps
1st Jul 2020, 10:29 PM
Uri Easter
Uri Easter - avatar
1st Jul 2020, 11:04 PM
Uri Easter
Uri Easter - avatar
+ 8
No worries. Is this any better?
1st Jul 2020, 11:05 PM
Uri Easter
Uri Easter - 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
Uri Easter
Uri Easter - avatar
+ 4
Please where exactly? Shewe Uchi K
1st Jul 2020, 10:22 PM
Chimamanda Unachukwu
Chimamanda Unachukwu - 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 Unachukwu
Chimamanda Unachukwu - 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 Unachukwu
Chimamanda Unachukwu - avatar
+ 3
Thank you guys for your help
5th Jul 2020, 12:34 PM
Chimamanda Unachukwu
Chimamanda Unachukwu - 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