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.
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.
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!')
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!
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
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()
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
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??
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():
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!')
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
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'
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?
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
@@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.
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.
thx ;)
@@wokchicken7734 np
Does this also work?
print(f"It took you {count} guess(es) to guess the answer!")
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.
i love the fact that he explains what every variable does
BRO THX FOR THE HELP I REALLY ENJOYED THE VID KEEP IT UP HAVE A GOOD DAY
You are the best teacher, thank you!
Flag= true
While flag is used to set up a while loop
I was studying the while loop and your video gave me the answer i've been searching for. Thanks. Subscribed
video instructions are very clear, and I love how you told us why you were writing that command, keep it up!
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!')
This'll help with my assignment for credits thanks Tim!
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!
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.
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
you should have used int(input("type a number for an upperbound: " ) .You gain much more time
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 :)
You would make a good teacher. Keep it up. Wish you lots of blessings
thanks bro you just helped me on my final project
What did you get on it cuz i have a project just like that
@@Mikuhassubscribers
I got a 87% on it. straight copy paste.
@@bread_outlaw3198 that's not half bad
Thank you soooooooo much for explaining this and not just rushing!!!
Why don’t we directly take integer as a input by
num = int(input(“Enter number : “))
?
the error will come in the code he did it looks good
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
It is very helpul thank you 🙏🙏
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.
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
@@thepeeps191 think his assignment is already finished 😂
@@JinnaB er...?
@@JinnaB lol yeah. Just for other viewers like you lolol
@@thepeeps191 aight thx bro
the video helped me a lot thanks bro
Thanks! Quick question: why do you put the empty parentheses after 'ifguess.isdigit ()' ?
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()
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
thanks for the help man really appericated it
Which algorithm is used in this game ?
Hi thanks for the vid. It rerally helped!
Np!
"rerally" you meant really
@@henryward8311 ye
@@teren2461 Are u still learning Python?
How do you limit the number of guesses?
maybe put everything in an while loop and break it when guess == ()
10 months late lol
Can this be done on spyder?
Nice video, thanks a lot !
thank u
i also make video about Guessing number game using android studio ,hope u see it
why u use if if and not if elif ?
thanks so much dude
How do you intend it 🙌🏻
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??
why?
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??
Thank you for this video!
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():
Me too
helped a lot
A code to ask if the user wants to continue or not
Bro in words or in string how it should be done bro
Where are u from bro??
How do I put a gui with this
very helpful .thank you
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!')
this was a life saver
But after the if guess.isdigit(): it does not run ...it shows invalid syntax why?
thank you so much
How do i run it
Nice vid
Thank you!
how can i make it so that it only plays 3 times and breaks
Thanks
dis is pog :D
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
You should be a teacher
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'
how to prevent this app close after finish his code????
I don't understand why you need to add the line num = int(num). Can someone please explain? Thanks!!!
it is type conversion to convet string to int type
it says that digit isnt defined
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?
Write after " if guess.isdigit():
guess = int(guess)"
if guess > secret :
print ("Down")
if guess< secret :
print ("Up")
Very helpful and thank you ...
download?
Hey, could anyone explain the significance of "import random" to me?
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
@@jorgesalazar2983 hey! Thank you, I ran into import math earlier today as well, great to know
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?
Check the "count" variable and when it hits 5 add a print statement to that effect.
John Billot Thank youu!!
@@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.
How is your code?
Try this version: ruclips.net/video/B161emPL2hg/видео.html
share the code
It doent work for me
Kieran Williams it might be because it’s been updated
Try this version: ruclips.net/video/B161emPL2hg/видео.html
not working
Try this version: ruclips.net/video/B161emPL2hg/видео.html
thanks