Random Number Guessing Game - Python (Beginners)

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

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

  • @mehthab1916
    @mehthab1916 3 года назад +18

    If figured out an extra function you can add:
    Instead of just typing : print('It took you', count, 'guesses')
    You can type:
    if count == 1:
    print('It took you', count, 'guess!')
    else:
    print('It took you', count, 'guesses!')
    So that will not add an "s" if you got it in one try but it will add an "s" if u got it after 2+ guesses.

  • @yosefambe789
    @yosefambe789 3 месяца назад

    Pretty good tutorial for beginners.
    A functionality I want to add is for the while True, to play many times, at the end of the game you can add:
    next_game = input('Do you want to play again (yes/no): ').lower()
    if next_game == 'yes':
    print('Excellent. You will play again!')
    elif next_game == 'no':
    break
    else:
    print('Invalid input. Enter yes or no')
    This way, the user can decide whether or not he wants to play again after guessing the number.

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

    i love the fact that he explains what every variable does

  • @punkhua9984
    @punkhua9984 4 года назад +11

    BRO THX FOR THE HELP I REALLY ENJOYED THE VID KEEP IT UP HAVE A GOOD DAY

  • @noone-gr4is
    @noone-gr4is 4 года назад +17

    You are the best teacher, thank you!

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

    Flag= true
    While flag is used to set up a while loop

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

    I was studying the while loop and your video gave me the answer i've been searching for. Thanks. Subscribed

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

    video instructions are very clear, and I love how you told us why you were writing that command, keep it up!

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

    if anyone is lazy to type it
    import random
    flag = True
    while flag:
    num = input('Type a number for an upper bound: ')
    if num.isdigit():
    print("Let's play!")
    num = int(num)
    flag = False
    else:
    print('Invalid input! Try Agien!')
    secret = random.randint(1,num)
    guess = None
    count = 1
    while guess != secret:
    guess = input('Please type a number between 1 and ' + str(num) + ": ")
    if guess.isdigit():
    guess = int(guess)
    if guess == secret:
    print('You got it!')
    else:
    print('Please try agien!')
    count += 1
    print('It took you', count, 'guesses!')

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

    This'll help with my assignment for credits thanks Tim!

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

    this is a little more complicated than it needs to be, i'm making a similar video myself and looking for inspiration, but there's multiple ways to make it and if it works it works. Good Video!

  • @lokeshjadhav9724
    @lokeshjadhav9724 5 лет назад +4

    Hey Tim nice video. You can make a next version of this by showing bisection / binary search and how we can solve this problem with this technique.

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

    import random
    random_number = random.randint(1,11)
    while True:
    try:
    guess = int(input("Guess a number from 1 to 10: "))
    if random_number != guess:
    if random_number

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

    you should have used int(input("type a number for an upperbound: " ) .You gain much more time

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

    Hello guys, to test your understanding you should add a clause that tells you if the secret number is higher or lower than your guess :)

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

    You would make a good teacher. Keep it up. Wish you lots of blessings

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

    thanks bro you just helped me on my final project

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

      What did you get on it cuz i have a project just like that

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

      @@Mikuhassubscribers
      I got a 87% on it. straight copy paste.

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

      @@bread_outlaw3198 that's not half bad

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

    Thank you soooooooo much for explaining this and not just rushing!!!

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

    Why don’t we directly take integer as a input by
    num = int(input(“Enter number : “))
    ?

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

      the error will come in the code he did it looks good

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

    Ohh I enjoyed making this just fun to take a brake from making a big game and too lay it down and code summit fun

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

    It is very helpul thank you 🙏🙏

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

    thanks for the video but I have a question. How can we add a question to user play again or not? I need this for my assignment.

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

      make a while loop before the while loop. at the end for the correct, do player_ans = input("continue? y/n
      ") if player_ans == "n": break

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

      @@thepeeps191 think his assignment is already finished 😂

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

      @@JinnaB er...?

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

      @@JinnaB lol yeah. Just for other viewers like you lolol

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

      @@thepeeps191 aight thx bro

  • @justpain.6523
    @justpain.6523 2 года назад

    the video helped me a lot thanks bro

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

    Thanks! Quick question: why do you put the empty parentheses after 'ifguess.isdigit ()' ?

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

    here is another version, and still 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()

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

    Hopefully you see this but what if i wanted to make a game where i could count to infinite amounts one number at a time like 1, 2, 3, 4
    but if i mess up say 1,2,3,5 it restarts to 0 and i have to count 1,2,3,4,5 until i mess up again. How could i do something like that? hopefully you understand... Using Python plz

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

    thanks for the help man really appericated it

  • @1gagandeepsingh373
    @1gagandeepsingh373 2 года назад

    Which algorithm is used in this game ?

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

    Hi thanks for the vid. It rerally helped!

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

    How do you limit the number of guesses?

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

      maybe put everything in an while loop and break it when guess == ()
      10 months late lol

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

    Can this be done on spyder?

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

    Nice video, thanks a lot !

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

    thank u
    i also make video about Guessing number game using android studio ,hope u see it

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

    why u use if if and not if elif ?

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

    thanks so much dude

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

    How do you intend it 🙌🏻

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

    I have to make this game for my project for school, but in the project I have to make the computer guess the number, not us...soo, how do we do that??

  • @ΑθανασίαΕιρήνηΓκαρίπη

    So i made a Pythagorean Triad finder (sorry if i am spelling wrong) and the program bugs after some time finding random triads and if i do it without random it works fine what is wrong??

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

    Thank you for this video!

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

      I have 2 problems with this code I need your help please
      1. I am having an infinite loop on the while loop
      2. I ran into an error on the second .isdigit():

    • @Melodic_Soul_0411
      @Melodic_Soul_0411 7 месяцев назад

      Me too

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

    helped a lot

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

    A code to ask if the user wants to continue or not

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

    Bro in words or in string how it should be done bro

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

    Where are u from bro??

  • @teahrodrigues-chavez7109
    @teahrodrigues-chavez7109 2 года назад

    How do I put a gui with this

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

    very helpful .thank you

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

    import random
    flag = True
    while flag:
    num = input('Type a number for an upper bound: ')
    if num.isdigit():
    print ("Let's play!")
    num = int(num)
    flag = False
    else:
    print('Invalid input! Try Again!')
    secret = random. randint(1,num)
    guess = None
    count = 1
    while guess != secret:
    guess = input('Please type a number between 1 and ' + str(num) + ": ")
    if guess. isdigit () :
    guess = int(guess)
    if guess == secret:
    print("You got it!")
    else:
    print('Please try again!')
    count += 1
    print('It took you', count, 'guesses!')

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

    But after the if guess.isdigit(): it does not run ...it shows invalid syntax why?

  • @mr.noobtophat3012
    @mr.noobtophat3012 4 года назад

    thank you so much

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

    How do i run it

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

    Nice vid

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

    how can i make it so that it only plays 3 times and breaks

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

    Thanks

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

    dis is pog :D

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

    I coded on 3.10.9 and when I got it wrong, nothing appeared like "you're wrong" and when I got it correct, I got kicked out immediatly why? I think its because the version

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

    You should be a teacher

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

    Anyone can 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 in ('Yes', 'No'):
    break
    play = answer == 'yes'

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

    how to prevent this app close after finish his code????

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

    I don't understand why you need to add the line num = int(num). Can someone please explain? Thanks!!!

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

      it is type conversion to convet string to int type

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

    it says that digit isnt defined

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

    i need something different, you have to guess a number between 1, 100( With 2 random Numbers generated) based on the number of the dice roll(1,6). if you guest incorrect it needs to tell you if you are to high/low or out of range. can someone please help?

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

      Write after " if guess.isdigit():
      guess = int(guess)"
      if guess > secret :
      print ("Down")
      if guess< secret :
      print ("Up")

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

    Very helpful and thank you ...

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

    download?

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

    Hey, could anyone explain the significance of "import random" to me?

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

      That’s the command to import “random” which is a library that has commands such as random.randint(1,20) which automatically selects a value between 1 and 20

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

      @@jorgesalazar2983 hey! Thank you, I ran into import math earlier today as well, great to know

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

    Hello, what if I wanted to have the user have a maximum of 5 tries, does anyone have any idea as to how I could do that?

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

      Check the "count" variable and when it hits 5 add a print statement to that effect.

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

      John Billot Thank youu!!

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

      @@eabadanna2492 You're welcome. It's an interesting learning task, experiment with the loop and where your check goes. How do you break out of the loop to stop further guesses etc. Enjoy, and good luck with your programming.

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

      How is your code?

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

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

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

    share the code

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

    It doent work for me

    • @Dominic.Hughes
      @Dominic.Hughes 4 года назад

      Kieran Williams it might be because it’s been updated

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

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

  • @Jessica-ue5uj
    @Jessica-ue5uj 4 года назад

    not working

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

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

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

    thanks