Building a Guessing Game | Python | Tutorial 21

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024

Комментарии • 111

  • @GabrieleValentini
    @GabrieleValentini 6 лет назад +22

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

    • @garvitahuja9097
      @garvitahuja9097 5 лет назад

      wrong

    • @Ryan_Parmelee
      @Ryan_Parmelee 5 лет назад +2

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

    • @eloghosaomorogbe9143
      @eloghosaomorogbe9143 4 года назад

      Too long process

    • @tsareena5899
      @tsareena5899 4 года назад +1

      Check this out:
      secret_word = "Giraffe"
      guess = ""
      guess_count = 0
      while guess != secret_word:
      if guess_count

    • @DailyBookInsights
      @DailyBookInsights 4 года назад

      @@Ryan_Parmelee 4

  • @karlson9036
    @karlson9036 Год назад +1

    I loved this tutorial! I spent a lot of time adding extra functions to my guessing game and expanding this! thank you!

  • @Ryan_Parmelee
    @Ryan_Parmelee 5 лет назад +14

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

    • @tsareena5899
      @tsareena5899 4 года назад +4

      Check this out:
      secret_word = "Giraffe"
      guess = ""
      guess_count = 0
      while guess != secret_word:
      if guess_count

    • @andeemengaming5000
      @andeemengaming5000 3 года назад +3

      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

    • @alishbaabubakr6975
      @alishbaabubakr6975 2 года назад

      This really helped
      Thanks

  • @hominakra377
    @hominakra377 4 года назад +2

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

  • @ozwrangler.c
    @ozwrangler.c 2 года назад

    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 RUclips ...so glad to find your channel 😍

  • @mikeafter5
    @mikeafter5 5 лет назад +8

    The second review was very helpful. Thanks!

  • @AjayKumar-ln1vf
    @AjayKumar-ln1vf 5 лет назад +4

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

  • @yohanes8006
    @yohanes8006 5 лет назад +1

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

  • @SYDNEYMALAMA-r8h
    @SYDNEYMALAMA-r8h 3 месяца назад

    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?

  • @theundergroundsm
    @theundergroundsm 5 лет назад +2

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

  • @tsareena5899
    @tsareena5899 4 года назад +12

    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

    • @japhethachimba174
      @japhethachimba174 2 года назад

      awesome

    • @ozwrangler.c
      @ozwrangler.c 2 года назад

      Kudos... like how you've simplified. Mike's example explains the concepts better.

  • @anandrao2308
    @anandrao2308 2 года назад

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

  • @swapnilrandhir492
    @swapnilrandhir492 4 года назад +1

    Congrats on 100 k subscribers !🎉

  • @sweetlar5485
    @sweetlar5485 2 года назад +1

    This is REALLY GOOD!! You explain really well. Thank you!

  • @andregomes7194
    @andregomes7194 2 года назад

    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-ElAbdi
    @Abdelhalim-ElAbdi 3 года назад +2

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

  • @ashikurrahamanshuvo1012
    @ashikurrahamanshuvo1012 5 лет назад

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

  • @ranjanadissanayaka5390
    @ranjanadissanayaka5390 2 года назад +1

    hell yeah..I got my code right..... thanks so much Mike.

  • @choppinhatiroagudo9200
    @choppinhatiroagudo9200 4 года назад +1

    thank you, your video saved me from a probleam.

  • @zandovic
    @zandovic 5 лет назад +2

    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"

    • @miikurr1194
      @miikurr1194 3 года назад +2

      2 years late but i think its simply just to make the script more readable

  • @kevinnisbet5648
    @kevinnisbet5648 4 года назад +3

    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()

    • @oceansblue692
      @oceansblue692 4 года назад

      Your Code is epic & educational. Thanks for sharing.
      Do you think you can look at my code?

    • @kevinnisbet5648
      @kevinnisbet5648 4 года назад +1

      @@oceansblue692 Thanks! Sure send it across

    • @oceansblue692
      @oceansblue692 4 года назад

      @@kevinnisbet5648 I did share it in the comments, if you scroll up, you will find it.
      Much appreciated.

    • @kevinnisbet5648
      @kevinnisbet5648 4 года назад

      @@oceansblue692 Ok, please check,

  • @jaydaoubarbar7452
    @jaydaoubarbar7452 2 года назад

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

  • @mehndi_with_aanchal3254
    @mehndi_with_aanchal3254 2 года назад

    Like your videos the most👏👏
    The way u teach is amazing n helpful 🙌

  • @nicatgenceliyev3554
    @nicatgenceliyev3554 4 года назад

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

    • @JackEacher
      @JackEacher 2 года назад

      i think you missed "else:" before the "print("you win")"?

    • @nicatgenceliyev3554
      @nicatgenceliyev3554 2 года назад +1

      @@JackEacher yes you are true

  • @determinationkaseke
    @determinationkaseke 2 года назад

    I appreciate you a lot you made it easy to get it right for me.

  • @anandrao2308
    @anandrao2308 2 года назад

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

  • @qjz77
    @qjz77 5 лет назад +3

    secret = "giraffe"
    guess = ""
    guess_limit = 3
    while guess != secret and guess_limit > 0 :
    guess = input("Enter guess")
    guess_limit -=1
    if guess == secret:
    print("You win.")
    else:
    print("You lose.")

  • @leoamine2736
    @leoamine2736 5 лет назад +2

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

  • @FerriGamingXD
    @FerriGamingXD 2 года назад

    This channel is good ilove it!

  • @Meeeemawwww
    @Meeeemawwww 5 лет назад +1

    My assignment for class says I have to use for statements. not while loops

  • @arenxou9914
    @arenxou9914 4 года назад +2

    Why do we need to set the guess=""? And why is it blank?

    • @Al-he6bs
      @Al-he6bs 4 года назад

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

    • @andeemengaming5000
      @andeemengaming5000 3 года назад +1

      @@Al-he6bs i think you just removed the guess variable

    • @anxiousearth680
      @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.

  • @determinationkaseke
    @determinationkaseke 2 года назад

    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
      @anxiousearth680 Год назад

      Can you post your code here? I'd like to see.

  • @Chirrup...
    @Chirrup... 4 года назад

    Thank . I just need to see how to do the loop and break thing

  • @Maldive177
    @Maldive177 3 года назад +1

    instead of the guessing game, password entering may be a better example")....

  • @Eric-dd8bk
    @Eric-dd8bk 3 года назад

    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.

  • @DailyBookInsights
    @DailyBookInsights 4 года назад

    #"try again" statement included
    password=""
    guess_count=0
    guess_limit=5
    secret_word="hello"
    while password!=secret_word and guess_count

  • @kkeith49
    @kkeith49 4 года назад +1

    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

    • @tannerabraham4590
      @tannerabraham4590 4 года назад

      Try this: ruclips.net/video/B161emPL2hg/видео.html

  • @bryansanchez8314
    @bryansanchez8314 4 года назад

    Thanks like your videos they help me a lot and you explain it so good

  • @NicoV2
    @NicoV2 3 года назад

    thanks for da code now i found my wae of programming :D

  • @steev708
    @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")

  • @space9342
    @space9342 6 месяцев назад

    tried my own before watching the code was functional :
    no_of_attempts=1
    guess_word =""
    while no_of_attempts

    • @overdoseonmynuts
      @overdoseonmynuts 4 месяца назад

      what if u wanted the guess word to be more than one word or number?

  • @aymans.portfolio
    @aymans.portfolio 2 года назад

    thanks, sir!

  • @duurduranto
    @duurduranto 4 года назад +1

    Much appreciated !!!

  • @naeemhussain5993
    @naeemhussain5993 3 года назад

    Good vid, learnt alot

  • @StickyDucky
    @StickyDucky 3 года назад

    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?

    • @penta5421
      @penta5421 3 года назад

      I would love to help, but I'd need to see your code for that

  • @im_yule
    @im_yule 11 месяцев назад

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

  • @marialilianjemmontero8800
    @marialilianjemmontero8800 2 года назад

    hello uh, what software are you using?

  • @stametnunukan4137
    @stametnunukan4137 4 года назад

    how to answer guess the secret number have six digit code 0-999999, do you have some trick, help please

  • @adithyanm9067
    @adithyanm9067 6 лет назад +1

    is there any loop like while not in python

    • @McBoccher
      @McBoccher 6 лет назад

      while not True
      while False
      while 1 == 2

  • @HiruniAbeysekara-fl1ij
    @HiruniAbeysekara-fl1ij 2 месяца назад

  • @asheshgupta4845
    @asheshgupta4845 Год назад

    Can someone tell me why we use booleans here?

  • @typeterson8376
    @typeterson8376 3 года назад

    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?

    • @penta5421
      @penta5421 3 года назад +2

      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.

    • @typeterson8376
      @typeterson8376 3 года назад

      @@penta5421 Thank you sir

    • @penta5421
      @penta5421 3 года назад

      @@typeterson8376 No problem!

  • @bhanushahi2182
    @bhanushahi2182 4 года назад

    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?

    • @JackEacher
      @JackEacher 2 года назад +1

      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

  • @tareqalalwan
    @tareqalalwan 5 лет назад

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

    • @gus3301
      @gus3301 5 лет назад

      what about if you want to set multiple passwords ?

    • @Ryan_Parmelee
      @Ryan_Parmelee 5 лет назад

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

  • @harshitanaik8824
    @harshitanaik8824 4 года назад

    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-bu5wh
      @CK-bu5wh 3 года назад

      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

    • @harshitanaik8824
      @harshitanaik8824 3 года назад

      @@CK-bu5wh Thank you !🙃

  • @ahmedmanzar6351
    @ahmedmanzar6351 5 лет назад +2

    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.

  • @oceansblue692
    @oceansblue692 4 года назад

    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()

    • @kevinnisbet5648
      @kevinnisbet5648 4 года назад +1

      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

    • @oceansblue692
      @oceansblue692 4 года назад

      @@kevinnisbet5648 Brilliant!

    • @oceansblue692
      @oceansblue692 4 года назад

      @@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 :)

    • @kevinnisbet5648
      @kevinnisbet5648 4 года назад +1

      @@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?

    • @oceansblue692
      @oceansblue692 4 года назад

      @@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!

  • @p.mousumipriyadarshini8677
    @p.mousumipriyadarshini8677 4 года назад

    you are very cool dude😎

  • @aartipurandare323
    @aartipurandare323 5 лет назад

    Hi good one

  • @BhojrajoO
    @BhojrajoO 2 года назад

    🙏

  • @ahmedborhan7252
    @ahmedborhan7252 3 года назад

    It is not working in phone🥺🥺😣

  • @fictionaddiction4706
    @fictionaddiction4706 5 лет назад +2

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

  • @arturw5390
    @arturw5390 3 года назад

    sick..

  • @logaprasath8287
    @logaprasath8287 Год назад

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

  • @Dexter21norman
    @Dexter21norman 4 года назад

    legend

  • @fredy749
    @fredy749 3 года назад +2

    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.