Is there any other way to make this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is there any other way to make this?

Is there any other THING that i can use instead of the whole out_of_guesses, true, not(out_of_guesses) method. I wasn't able to digest the method. I'm continuously thinking of some other way. And what is the THING called (technically) https://code.sololearn.com/cWQv5URpPmZL/?ref=app

21st Jun 2019, 3:00 PM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
11 Answers
+ 2
Theres many ways to do it. But here's a cool one that is very unique to python, using a while/else statement: while word_count < count_limit: guess = input(...) if(guess == secret_word): print("You win!") break word_count += 1 else: print("You lose.")
21st Jun 2019, 3:38 PM
Schindlabua
Schindlabua - avatar
+ 1
In SoloLearn non-web-playgrounds, using input statement in loops could cause errors.
21st Jun 2019, 3:03 PM
Seb TheS
Seb TheS - avatar
+ 1
Akhil Padmanabhan, I might be able to support if there particular things you are struggling with
22nd Jun 2019, 7:16 PM
ChrA
ChrA - avatar
0
Seb TheS well I know that.. I used jupyter to run it, but I wanted something smaller and simpler instead of out_of_guesses..
21st Jun 2019, 3:15 PM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
0
Hey. How about changing to a for loop in range (max_guesses - 1) and break if the guess was right? Hope that helps. Cheers. C
21st Jun 2019, 3:38 PM
ChrA
ChrA - avatar
0
Sorry, I rushed, but you could use a for loop and a list instead of counter and while loop. class OutOfGuesses(Exception): pass a_l = [None, None, None] for a in a_l: if guess_wrong: continue elif guess_whole: break elif guess_any: a_l.append(None) else: raise OutOfGuesses print("You guessed the whole word!")
21st Jun 2019, 3:42 PM
Seb TheS
Seb TheS - avatar
0
Schindlabua thank you.. It worked like knife over butter.. Well the "while... Else.." is new to me.. Thanks again!!
22nd Jun 2019, 3:18 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
0
Seb TheS Is this the entire code? I'm still a noob and classes aren't my specialisation.. How do I define guess_wrong and thus every guess_variable?
22nd Jun 2019, 3:30 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
0
ChrA can you type in the code for me please.. It would be more helpful..
22nd Jun 2019, 3:32 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar
0
That class, I only created an error with a nice name.
22nd Jun 2019, 5:33 AM
Seb TheS
Seb TheS - avatar
0
Seb TheS can you type in the entire code please.. It would help me to understand it better..
22nd Jun 2019, 10:38 AM
Akhil Padmanabhan
Akhil Padmanabhan - avatar