This was my "Guessing game", before checking the way you did it :D secret_word = "giraffe" guess = "" attempt = 3 while guess != secret_word and attempt >= 1: attempt -= 1 guess = input("Enter guess: ") if attempt == 1: print("You still have " + str(attempt) + " attept") elif attempt == 0: print("You have no more attempts!") else: print("You still have " + str(attempt) + " attepts") if guess == secret_word: print("You win!") else: print("You lose!")
@garvitahuja90975 жыл бұрын
wrong
@Ryan_Parmelee5 жыл бұрын
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement. secretWord = "python" guess = "" guessCount = 0 while guess != secretWord: if guessCount == 3: break else: guess = input("Enter a guess: ") guessCount += 1 if guess == secretWord: print("You Win!") else: print("You Loose!")
@eloghosaomorogbe91435 жыл бұрын
Too long process
@tsareena58994 жыл бұрын
Check this out: secret_word = "Giraffe" guess = "" guess_count = 0 while guess != secret_word: if guess_count
@DailyBookInsights4 жыл бұрын
@@Ryan_Parmelee 4
@karlson9036 Жыл бұрын
I loved this tutorial! I spent a lot of time adding extra functions to my guessing game and expanding this! thank you!
@Ryan_Parmelee5 жыл бұрын
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement. secretWord = "python" guess = "" guessCount = 0 while guess != secretWord: if guessCount == 3: break else: guess = input("Enter a guess: ") guessCount += 1 if guess == secretWord: print("You Win!") else: print("You Loose!")
@tsareena58994 жыл бұрын
Check this out: secret_word = "Giraffe" guess = "" guess_count = 0 while guess != secret_word: if guess_count
@andeemengaming50004 жыл бұрын
your spelling of "lose" is wrong cuz what you spelt means the opposite of "tight" lol jk i know its an error anyway nice code
@Allisonpeers010102 жыл бұрын
This really helped Thanks
@ozwrangler.c2 жыл бұрын
Just used this video as an example of the best way to teach code to beginners. My course has all the abstract ideas (variables, iteration, etc.) followed by examples. IMO, that's an arse-about way to teach coding. My course content was so confusing I came to KZbin ...so glad to find your channel 😍
@AjayKumar-ln1vf5 жыл бұрын
My way of doing word = "Guess" guess_word = "" limit = 3 while word != guess_word and limit != 0: guess_word = input("Enter word : ") limit -= 1 if word == guess_word: print("You win") else: print("You Lose")
@yohanes80065 жыл бұрын
make it simple, secret_word = "giraffe" guess = "" guess_count = 0 while guess != secret_word and guess_count < 3: guess = input("Enter a guess: ") guess_count += 1 if guess != secret_word: print("You lose!") else: print("You win!")
@mikeafter55 жыл бұрын
The second review was very helpful. Thanks!
@hominakra3774 жыл бұрын
This was my guessing game before watching his brilliant idea.... sw = "Insane" guess = "" attempt = 3 print("Hint :- Gopal") while guess != sw and attempt > 0: print("You have", attempt, "attempts left") guess = input("Enter your guess: ") attempt -= 1 if guess != sw: if attempt < 1: print("You lose") elif attempt > 1: print("try harder") elif guess == sw: print("Well Done")
@SYDNEYMALAMA-r8h4 ай бұрын
Write a program in Python for the following numerical game with additional features: The computer stores a random number between 1 and 100. The player (user) attempts to guess the number. The player has a total of five attempts. After each wrong guess, the computer tells the user if the number was too high or too low. If the fifth attempt is also wrong, the number is output on screen. The player wins if he or she can guess the number within five attempts. The player is allowed to repeat the game as often as he or she wants. Track the number of games played and the number of wins. Provide an option to view the game statistics (number of games played, number of wins, and win percentage). Implement input validation to ensure the user enters a valid number within the specified range. Use object-oriented principles: Create classes for the game logic, player statistics, and user interface. Add exception handling to manage unexpected errors who can finish this code?
@swapnilrandhir4924 жыл бұрын
Congrats on 100 k subscribers !🎉
@tsareena58994 жыл бұрын
using this guy's vid for understanding the language since I knew C from my school. Really he deserves to be known! I made this simplified version with less variables but with a break. Check it out ^_^ secret_word = "Giraffe" guess = "" guess_count = 0 while guess != secret_word: if guess_count
@japhethachimba1742 жыл бұрын
awesome
@ozwrangler.c2 жыл бұрын
Kudos... like how you've simplified. Mike's example explains the concepts better.
@theundergroundsm5 жыл бұрын
My Guessing game code word = "refer" guess = "" guess_number = 0 guess_limit = 5 while guess != word and guess_number < guess_limit: guess = input("Enter the word: ") guess_number += 1 if guess != word: print("Try again!") if guess == word: print("You guessed the word!") else: print("You failed!")
@sweetlar54852 жыл бұрын
This is REALLY GOOD!! You explain really well. Thank you!
@ranjanadissanayaka53902 жыл бұрын
hell yeah..I got my code right..... thanks so much Mike.
@andregomes71942 жыл бұрын
import random x= random.randrange(o,15) list= "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" print(list) n=int(input('insere um número entre 0-15':)) while n!= x: print("errado! tente de novo") if x>n: print('adivinha um número maior') n=int(input('Insere outro número')) else: print('adivinha um número maior') n=int(input(Insere outro número' )) print('Está certo!') ~
@Abdelhalim-ElAbdi3 жыл бұрын
I eneded up with a compact version of the code lemme know if it has any flows. Thank you secret_word = "Giraffe" guess = "" tries = 0 while secret_word != guess and tries < 3: guess = input("Please type your guess: ") tries += 1 if tries == 3 : print("You run out of chances") elif guess == secret_word: print("You won ")
@anandrao23082 жыл бұрын
secret_word="Test" guess="" trynumber=0 while guess!=secret_word : guess=input("Enter Guess : ") #print("try again") trynumber += 1 if trynumber>=3: #print("break") break if trynumber>=2 and guess!=secret_word: print("Your limit crossed") if guess==secret_word : print("You win ")
@zandovic5 жыл бұрын
Fantastic tutorial! Is there a reason for why you use the variable "guess_limit" instead of just 3? Then you would just need to write "if guess_count < 3" instead of "if guess_count < guess_limit"
@miikurr11943 жыл бұрын
2 years late but i think its simply just to make the script more readable
@mehndi_with_aanchal32542 жыл бұрын
Like your videos the most👏👏 The way u teach is amazing n helpful 🙌
@arenxou99144 жыл бұрын
Why do we need to set the guess=""? And why is it blank?
@Al-he6bs4 жыл бұрын
Same question. But I found something more understandable code for this that do not require variable "guess". Here it is: secret_word = "Giraffe" guess_count = 0 guess_limit = 3 while guess_count < guess_limit: guess = input("Guess: ") guess_count += 1 if guess == secret_word: print ("You won!) break else: print("You lose..")
@andeemengaming50004 жыл бұрын
@@Al-he6bs i think you just removed the guess variable
@anxiousearth680 Жыл бұрын
I think, otherwise python will throw an error when guess is used as the condition after the While statement. Either because the variable needs to be defined first or because it needs to have some sort of value to be used. It's empty because the value will be redefined by Input in the loop anyway, so it doesn't matter what it contains at first.
@choppinhatiroagudo92004 жыл бұрын
thank you, your video saved me from a probleam.
@ashikurrahamanshuvo10125 жыл бұрын
Guessing Game (before i watch the video) secret_number = 7 guess = "" count = 0 while secret_number != guess and count != 5: guess = int(input("Enter the Guess : ")) count += 1 if count == 5: print("You fail!") else: print("you win!")
@Meeeemawwww5 жыл бұрын
My assignment for class says I have to use for statements. not while loops
@determinationkaseke2 жыл бұрын
I appreciate you a lot you made it easy to get it right for me.
@kevinnisbet56484 жыл бұрын
Here is my code in which i made a list of words and made a function to chose randomly, also has a scoring system. Any feedback would be helpful thanks import random words = ['ant', 'bee', 'cat', 'dog', 'egg', 'hat', 'golf', 'jelly', 'king', 'bird', 'hot', 'cold', 'fish', 'log', 'dad', 'mum', 'goal', 'help', 'frog', 'neat', 'car', 'moon', 'eye', 'tree', 'rice', 'ice', 'speed', 'rat', 'water', 'rain', 'snow', 'spoon', 'light', 'gold', 'zoo', 'oil', 'goat', 'yoga', 'judo', 'japan', 'hello', 'train', 'star', 'start', 'fork', 'teri', 'kevin', 'booker', 'deny', 'dojo', 'code', 'dodge', 'honey'] def choose_random_word(lst): # chooses a word then removes it from the list, to avoid repetition w = random.randrange(len(lst)) return lst.pop(w) def main_loop(): global player_score pick = choose_random_word(words) character_length = len(pick) print(" Round {} - score:{}".format(i, player_score)) print("The word has {} characters".format(character_length)) first_letter = pick[0] last_letter = pick[-1] print("The first letter is {}".format(first_letter.upper())) answer = input("\tEnter your answer: ") tries_count = 3 if answer == pick: print("\tGreat first try! 5 points") player_score += 5 else: print("The last letter is {}".format(last_letter)) while answer != pick and tries_count >= 0: answer = input("Please try again, you have {} tries left: ".format(tries_count)) tries_count -= 1 if character_length > 3: print("Letter {} is {}".format((tries_count+1), pick[tries_count])) if answer == pick: print("good 1 point") player_score += 1 if answer != pick and tries_count < 0: print("\tIncorrect. The correct word was {}".format(pick)) if player_score > 0: player_score -= 1 def print_score(): print(" Your total score was {}".format(player_score)) player_score = 0 times_to_play = 10 for i in range(1, 1 + times_to_play): main_loop() times_to_play += 1 print_score()
@oceansblue6924 жыл бұрын
Your Code is epic & educational. Thanks for sharing. Do you think you can look at my code?
@kevinnisbet56484 жыл бұрын
@@oceansblue692 Thanks! Sure send it across
@oceansblue6924 жыл бұрын
@@kevinnisbet5648 I did share it in the comments, if you scroll up, you will find it. Much appreciated.
@kevinnisbet56484 жыл бұрын
@@oceansblue692 Ok, please check,
@leoamine27365 жыл бұрын
My way of doing it: secret_word = "pyhton" guess = "" guess_count = 0 print("Welcome to our guessing game!") print("Enter a word and see if you guessed the secret one: ") while guess != secret_word and guess_count < 3: guess = input("Enter your guess: ") guess_count += 1 if guess == secret_word: print("That's right! You win.") else: print("Out of guesses! You lose.")
@kkeith494 жыл бұрын
Chiming in here in 2020 using Python 3.3 and I'm getting an error using the "input("Enter a guess: ")". I was only able to get the program to work if I used raw_input vs just input
@tannerabraham45904 жыл бұрын
Try this: kzbin.info/www/bejne/eGKZYpijhbFlnsk
@jaydaoubarbar74522 жыл бұрын
here is my version: secret_word = "carrot" guess = "" attempt = 3 hint = "" yes = "yes" while guess != secret_word and attempt >= 1: attempt -= 1 guess = input("Enter guess: ") if attempt == 1: print("You still have " + str(attempt) + " attempt") hint = input("Do you want a hint? ") if hint == yes: print("it is a vegetable") else: print("okay") elif attempt == 0: print("You have no more attempts!") else: print("You still have " + str(attempt) + " attempts") hint = input("Do you want a hint? ") if hint == yes: print("it is orange in color") else: print("okay") if guess == secret_word: print("You win!") else: print("You lose!")
@Eric-dd8bk3 жыл бұрын
I added a feature that asks the user whether they want to continue or quit when they get the wrong answer to this program and the user can respond by typing "y" or "n" for yes or no. Code below. word = "Giraf" guess = "" guess_count = 0 guess_limit = 2 out_of_guesses = False while guess != word and not out_of_guesses: if guess_count < guess_limit: guess = input("What's the word? ") guess_count += 1 else: out_of_guesses = True print("You lose.") break if guess == "giraf": print("You win!") break else: question = input("Do it again?") if question == 'y': print("One more try!") pass elif question == 'n': print("Okay. Goodbye.") break else: print("Invalid input.") Please let me know if anyone sees any flaws in the code. One possible flaw that I see that might come up is it asking me even when the user is out of guess chances.
@FerriGamingXD2 жыл бұрын
This channel is good ilove it!
@bryansanchez83144 жыл бұрын
Thanks like your videos they help me a lot and you explain it so good
@Chirrup...4 жыл бұрын
Thank . I just need to see how to do the loop and break thing
@ahmedmanzar63515 жыл бұрын
Hi Mike, In case if the secret_word/title is a book title with more than one word, how to search for a word or few letters using the while loop.
@determinationkaseke2 жыл бұрын
I got the code correct but my problem is, the phrase 'You won!' keeps appearing even without getting the secret word correct but after getting it correct it appears then no more options just like yours Sir. What binding am I missing
@anxiousearth680 Жыл бұрын
Can you post your code here? I'd like to see.
@nicatgenceliyev35544 жыл бұрын
and it is my opinion: secret_word = "giraffe" guess = "" tries = 3 while guess != secret_word: guess = input("Enter secret word: ") tries -= 1 if tries == 0: print("you lose") break print("you win")
@JackEacher2 жыл бұрын
i think you missed "else:" before the "print("you win")"?
@nicatgenceliyev35542 жыл бұрын
@@JackEacher yes you are true
@anandrao23082 жыл бұрын
secret_word="Test" guess="" trynumber=0 while guess!=secret_word : guess=input("Enter Guess : ") trynumber += 1 if guess!=secret_word: print("You have :" , abs(trynumber-2),"Guess left") #trynumber += 1 if trynumber>=3: #print("break") break if trynumber>=2 and guess!=secret_word: print("Your limit crossed") if guess==secret_word : print("You win ")
@adithyanm90676 жыл бұрын
is there any loop like while not in python
@McBoccher6 жыл бұрын
while not True while False while 1 == 2
@typeterson83763 жыл бұрын
Could someone explain why there had to be a global variable for guess with empty quotes. Would it have worked the same if the only variable for guess was the input inside of the whole loop?
@penta54213 жыл бұрын
That would not work, as the while loop checks for the guess variable before it is even declared inside the loop. Since the while loop comes before, declaring the variable only inside would give you an error, as the variable does not yet exist.
@typeterson83763 жыл бұрын
@@penta5421 Thank you sir
@penta54213 жыл бұрын
@@typeterson8376 No problem!
@NicoV23 жыл бұрын
thanks for da code now i found my wae of programming :D
@DailyBookInsights4 жыл бұрын
#"try again" statement included password="" guess_count=0 guess_limit=5 secret_word="hello" while password!=secret_word and guess_count
What's the use of , guess=" " , you said it's to store all guesses . What does that mean? is it only in things with user input? because we haven't done this in the former videos that had user input(mad lib game).
@TheRachana12344 жыл бұрын
use a list
@naeemhussain59933 жыл бұрын
Good vid, learnt alot
@asheshgupta4845 Жыл бұрын
Can someone tell me why we use booleans here?
@duurduranto4 жыл бұрын
Much appreciated !!!
@marialilianjemmontero88003 жыл бұрын
hello uh, what software are you using?
@anxiousearth680 Жыл бұрын
For python? Pycharm
@Maldive1773 жыл бұрын
instead of the guessing game, password entering may be a better example")....
@StickyDucky4 жыл бұрын
After writing the program, i tried to write down my secret word but need to type it down three times in order for me to "win". why is this so?
@penta54213 жыл бұрын
I would love to help, but I'd need to see your code for that
@space93427 ай бұрын
tried my own before watching the code was functional : no_of_attempts=1 guess_word ="" while no_of_attempts
@overdoseonmynuts6 ай бұрын
what if u wanted the guess word to be more than one word or number?
@im_yule Жыл бұрын
See this guys, I made it in more simple way : # simple guessing game : sec_word = "apple" # secret word chance_left = 3 # chance left for user user_guess = "" # user's guess word while sec_word != user_guess and chance_left != 0: print(">") user_guess = input("Enter your guess word : ") chance_left -= 1 if sec_word == user_guess: print("You are correct, Congratulation You won!") else: print("Finished chance, Sorry you lose! ")
@p.mousumipriyadarshini86774 жыл бұрын
you are very cool dude😎
@aymans.portfolio2 жыл бұрын
thanks, sir!
@stametnunukan41374 жыл бұрын
how to answer guess the secret number have six digit code 0-999999, do you have some trick, help please
@tareqalalwan5 жыл бұрын
My way of doing it :) : password = "Aladdin" answer = "" answer_limit = 3 answer_count = 0 while answer != password and answer_count < answer_limit: answer = input ("Enter your password: ") answer_count += 1 if answer == password: print ("Authorized!") else: print("You are not authorized!")
@gus33015 жыл бұрын
what about if you want to set multiple passwords ?
@Ryan_Parmelee5 жыл бұрын
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement. secretWord = "python" guess = "" guessCount = 0 while guess != secretWord: if guessCount == 3: break else: guess = input("Enter a guess: ") guessCount += 1 if guess == secretWord: print("You Win!") else: print("You Loose!")
@bhanushahi21824 жыл бұрын
Ask the user a question. Read his answer and check if his answer is right or not. If right, say the answer is right. If wrong, prompt him to guess again. He can guess a maximum of 5 times. Before the last guess, give him a “last guess” warning. If he cannot guess within 5 times, display that he/she . can anyone please solve this question?
@JackEacher2 жыл бұрын
secret_word = "cat" guess = "" guess_limit = 5 guesses = 0 while guess != secret_word: if guesses < guess_limit: guess = input("Enter a guess: ") guesses += 1 if guesses == 4: guess = input("LAST GUESS! Enter guess: ") guesses += 1 if guess == secret_word: print ("YOU WIN") break else: print ("YOU LOSE") break
@HiruniAbeysekara-fl1ij4 ай бұрын
@steev708 Жыл бұрын
I was not able understand your tutorial fully and i made my own code. But i guess something is wrong, can anyone tell where can i improve secret_word = "Ligma" guess = "" guess_count = 0 guess_limit = 4 while secret_word != guess: guess_count += 1 if guess_count < guess_limit: guess = input("Enter your guess: ") elif guess_count == guess_limit: print("Out of guesses you lose.") if guess == secret_word: print("You win")
@harshitanaik88244 жыл бұрын
Can anyone tell me what should we enter in the guess variable if we want to allow them to enter a number instead of a string . I mean we need to put "" even for numbers or anything else 🤔🤔 I'M REALLY NEW TO THIS!😅😅😅
@CK-bu5wh3 жыл бұрын
Int(input(enter a number plz!)) Another way to write/ N= Input(“Enter a number”) Int(n) So the int() function is to convert a string to a integer
@harshitanaik88243 жыл бұрын
@@CK-bu5wh Thank you !🙃
@oceansblue6924 жыл бұрын
Can't resolve the endless loop. it keeps asking "Would you like to play again?" Yes or No is not working properly import random as rd play = True while play: number = rd.randint(1, 20) guess = int(input("Guess a number between 1 and 20: ")) count = 0 while count < guess != number: count +=1 if guess > number: print(guess, "was too high. Try again.") if guess < number: print(guess, "was too low. Try again.") guess = int(input("Guess again!")) print(guess, "was the number! You win!", "well done in ", count, "tries") while True: answer = input('Would you like to play again?: ').lower() if answer == 'Yes': play = True continue # break elif answer == 'No': break else: answer = input('Incorrect option. Type "Yes" to try again or "No" to leave the game').lower()
@kevinnisbet56484 жыл бұрын
import random as rd def main_game(): play = True while play: number = rd.randint(1, 20) guess = int(input("Guess a number between 1 and 20: ")) count = 0 while count < guess != number: count += 1 if guess > number: print(guess, "was too high. Try again.") if guess < number: print(guess, "was too low. Try again.") guess = int(input("Guess again! ")) print(guess, "was the number! You win!", "well done in", count, "tries") play = False main_game() play_again = True while play_again: answer = input('Would you like to play again?: ').lower() if answer == 'yes': main_game() elif answer == 'no': quit() else: answer = input('Incorrect option. Type "Yes" to try again or "No" to leave the game: ').lower() ------------------------ Im sure there is a better solution but at least it works now :P
@oceansblue6924 жыл бұрын
@@kevinnisbet5648 Brilliant!
@oceansblue6924 жыл бұрын
@@kevinnisbet5648 One more thing, play the game, and instead of typing a guess number, type yes or no, code breaks. Also when the game ends, type in a number instead of yes or no to end the game, and it is still not accepting Yes or no 16 was the number! You win! well done in 6 tries Would you like to play again?: yes Incorrect option. Type "Yes" to try again or "No" to leave the gameYes Would you like to play again?: Yes Incorrect option. Type "Yes" to try again or "No" to leave the game Let's keep trying :)
@kevinnisbet56484 жыл бұрын
@@oceansblue692 for me the guessing is ok. Guess a number between 1 and 20: 10 10 was too low. Try again. Guess again! 15 15 was the number! You win! well done in 1 tries Would you like to play again?: yes Guess a number between 1 and 20: For me it works fine, if the input is fine. BUT if the code expects a int (number) and gets a char or a string it will cause an error, try using a try/except clause ** also after looking at this maybe start the tries from 1, it took me 2 tries but still says 1 tries. Also maybe use an if statement, if tries < 1 use try else tries .... if that makes sense?
@oceansblue6924 жыл бұрын
@@kevinnisbet5648 Makes sense. Except that i am not that good yet. "using a try/except clause" never used. "an if statement, if tries < 1 use try else tries" Will keep trying. Thanks!
@aartipurandare3235 жыл бұрын
Hi good one
@ahmedborhan72523 жыл бұрын
It is not working in phone🥺🥺😣
@BhojrajoO2 жыл бұрын
🙏
@arturw53903 жыл бұрын
sick..
@fredy7493 жыл бұрын
I will never win a guess like this as I have never got a clue to answer to the game either guess the name of a wild animal or a tall animal in the world. Just give the user a lead.
@logaprasath82872 жыл бұрын
I tried different code. Pls let me know, any flaws in it. secret_word2 = "Surprise" guess1 = "" guess_count = 0 while guess1 != secret_word2 and guess_count < 3 : guess1 = input("Enter guess: ") guess_count += 1 if guess1 == secret_word2 : print ("You win!") elif guess_count < 3 : print("Try again") else : print ("You lose!")