Let's code a Python NUMBER GUESSING GAME! 🔢

preview_player
Показать описание
This Python number guessing game for beginners will help us gain experience with using loops and random numbers. Code for this video can be found in the comments section.
Рекомендации по теме
Комментарии
Автор

# Python number guessing game
import random

lowest_num = 1
highest_num = 100
answer = random.randint(lowest_num, highest_num)
guesses = 0
is_running = True

print("Python Number Guessing Game")
print(f"Select a number between {lowest_num} and {highest_num}")

while is_running:

guess = input("Enter your guess: ")

if guess.isdigit():
guess = int(guess)
guesses += 1

if guess < lowest_num or guess > highest_num:
print("That number is out of range")
print(f"Please select a number between {lowest_num} and {highest_num}")
elif guess < answer:
print("Too low! Try again!")
elif guess > answer:
print("Too high! Try again!")
else:
print(f"CORRECT! The answer was {answer}")
print(f"Number of guesses: {guesses}")
is_running = False
else:
print("Invalid guess")
print(f"Please select a number between {lowest_num} and {highest_num}")

BroCodez
Автор

hey bro, I just wanna say that you have been an awesome mentor for me for the last few months, I'm currently in the middle of watching the 12 hour python course, I'm learning so much cool stuff thanks to you, I hope you're doing well and please keep up the good work, love from Bangladesh <3

anwu
Автор

This more intersting and helpful for beginers

mamunmondal-hern
Автор

*_Bro actually uploads this frequent?_*

Reymax
Автор

Shout out to you for making free videos that help us

Takiplay
Автор

Could you do an intermediate level Pygame tutorial where you make this same game using labels, buttons, and and input line?

nathanielhale
Автор

Heres how i did mine:

from random import randint


def main():
while True:

attempts = 0
random_choice = randint(1, 9)
while True:
try:
player_guess = int(input('Guess a number from 1 to 9: '))
if player_guess == random_choice:
attempts = attempts + 1
print(f'You guessed right! The number was {random_choice}.')
print(f'You needed {attempts} attempts to guess the number!')
break
else:
attempts = attempts + 1
print('You guessed wrong!')
except ValueError:
print('Please only type a integer number between 1 to 9.')


if __name__ == '__main__':
main()

if there's anything i could do better can someone please tell me?

spectrogames
Автор

number = random.randint(low, high)


why this happens

jomon-bqhz
Автор

Pakat video cah you also maké a video on python genarators and sqlite please i am 12 years old

শখেরবাড়ি৯৯০
Автор

here's my Number guessing game!

import random

random_limit = random.randint(5, 10)
print("Welcome to the Python Number Guessing Game!\nHere you have to GUESS a random number!")
print("And you have a random amount of trys\nGood

mode [1 - 20] \n2)Medium mode [1 - 50\n3)Hard mode [1 - 100]")
difficulty_level = int(input("> "))
if difficulty_level == 1:
b_number = 20
random_number = random.randint(1, 20)
elif difficulty_level == 2:
random_number = random.randint(1, 50)
b_number = 50
else:
random_number = random.randint(1, 100)
b_number = 100

count = 0
limit = random_limit
print(f"You have {limit} trys")


def main():
global count, limit

while count < limit:
try:
user_input = the number: "))

if count == limit:
print(f"Correct number was {random_number}")
elif user_input > b_number:
print("Choice out of range!")
main()

if user_input == random_number:
print(f"Correct! {random_number} was the correct answer!")
break
else:
print("Incorrect try again..")
if user_input > random_number:
print("Your Guess is a bit high try a new number!")
elif user_input < random_number:
print("Your Guess is a bit low try a new number!")
elif user_input > b_number or user_input < b_number:
print("Choice out of range!")
count += 1

except ValueError:
print("Enter a valid choice!")


if __name__ == '__main__':
main()

Codebro your my fav youtuber you helped me alot with your videos ♥

JustNars