+ 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
11 odpowiedzi
+ 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.")
+ 1
In SoloLearn non-web-playgrounds, using input statement in loops could cause errors.
+ 1
Akhil Padmanabhan, I might be able to support if there particular things you are struggling with
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..
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
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!")
0
Schindlabua thank you.. It worked like knife over butter.. Well the "while... Else.." is new to me..
Thanks again!!
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?
0
ChrA can you type in the code for me please.. It would be more helpful..
0
That class, I only created an error with a nice name.
0
Seb TheS can you type in the entire code please.. It would help me to understand it better..