Random Number Guessing Game - Python (Beginners)

preview_player
Показать описание
In this video I will be explaining how to create a random number guessing game in python. This is a beginner tutorial and will walk through step by step how everything is coded. In this video you will learn how to create a random number in python. How to to use while loops. How to check if values are equivalent and how to see if a string is a representation of a digit.

Want To Support This Channel?
Bitcoin: 1PbkAYLFaJBgjbKn2ptGyBz65xWN8hJgBU
Ethereum: 0xdd42dbbdba60f7163fc7a840e189474b6e8bfcad
Ripple: rD4arM9CVjQWqi8f1kxdpCgkCgEkqBgtud

Please leave a LIKE and SUBSCRIBE for more content!

Tags:
- Tech
- Tech With Tim
- Programming
- Coding
- Pygame
- Python Tutorials
- Random numbers python
- Random number guessing game python
- Beginner coding
- Beginner coding tutorial python
- How to make games in python
Рекомендации по теме
Комментарии
Автор

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.

mehthab
Автор

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.

yosefambe
Автор

i love the fact that he explains what every variable does

khenleyzephir
Автор

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

Movewithkhu
Автор

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 <= guess and guess <= 10:
print("Guess Lower")
elif random_number >= guess and guess <=10:
print("Guess Higher")
else:
print("Number have to be in the boundary of 1 to 10.")
else:
print("Your guess is correct.")
break
except:
print("Sorry, Invalid input")

sagarparajuli
Автор

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

punkhua
Автор

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

xxzillazaxx
Автор

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

Tarrmie
Автор

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

ahmedzahra
Автор

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

outcastongfuel
Автор

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!

channelemex_private
Автор

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

rutvikpathak
Автор

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

brooklynrobbo
Автор

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

smilenation
Автор

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

unearthlyfriends
Автор

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

joshfioramonti
Автор

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

bhgames
Автор

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

oceansblue
Автор

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

Zubrv
Автор

thanks bro you just helped me on my final project

bread_outlaw