Let's code a Python NUMBER GUESSING GAME! 🔢

  Рет қаралды 12,485

Bro Code

Bro Code

Күн бұрын

Пікірлер: 23
@BroCodez
@BroCodez 5 ай бұрын
# 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}")
@yasjudankhan
@yasjudankhan 9 күн бұрын
Uhh about the code, it adds +1 to the guesses variable even if the guess it out of range. So wouldn't it be better to have this instead? while is_running: guess = input("Enter your guess: ") if guess.isdigit(): guess = int(guess) if guess < lowest_num or guess > highest_num: print(f"Guess is out of range. Please select a number between {lowest_num} and {highest_num}") elif guess < a: guesses += 1 print("Too Low! Try again.") elif guess > a: guesses += 1 print("Too High! Try again.") else: guesses += 1 print(f"CORRECT! The answer was {answer}.") print(f"It took you {guesses} guesses.") is_running = False else: print(f"Please enter a NUMBER between {lowest_num} and {highest_num}") Correct me if I'm wrong. (I only gave the while loop part, cause everything before it is fine)
@anwu2196
@anwu2196 5 ай бұрын
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
@mamunmondal-he3rn
@mamunmondal-he3rn 5 ай бұрын
This more intersting and helpful for beginers
@Takiplay243
@Takiplay243 5 ай бұрын
Shout out to you for making free videos that help us
@karth885
@karth885 5 ай бұрын
Nice teaching
@nathanielhale5726
@nathanielhale5726 5 ай бұрын
Could you do an intermediate level Pygame tutorial where you make this same game using labels, buttons, and and input line?
@Reymax164
@Reymax164 5 ай бұрын
*_Bro actually uploads this frequent?_*
@mamunmondal-he3rn
@mamunmondal-he3rn 5 ай бұрын
He is my teacher through youtube
@zivb2010
@zivb2010 5 ай бұрын
please make a unity tutorial🥺🙏
@AyushSinhx
@AyushSinhx 4 ай бұрын
thanks
@jomon-bq8hz
@jomon-bq8hz 3 ай бұрын
number = random.randint(low, high) ^^^^^^^^^^^^^^ why this happens
@yazant5241
@yazant5241 5 ай бұрын
Can you teach us unity please ❤❤❤❤
@spectrogames8
@spectrogames8 5 ай бұрын
Heres how i did mine: from random import randint def main(): while True: print('*****************GUESS-THE-NUMBER*****************') 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?
@JustNars
@JustNars 5 ай бұрын
1)Make it 1 - 100 2)You know you can just use this attempts += 1 and not this attempts = attempts + 1 3)If you do make it 1 - 100 make hints 4)I think you make a typo on "_name_" cuz when I tried it I got a error over all your guessing game uses less lines I give it a 7/10
@TheLoneRoninYT
@TheLoneRoninYT 5 ай бұрын
What does if main == name mean
@fabiotucci3029
@fabiotucci3029 5 ай бұрын
​@@TheLoneRoninYTIt checks if the script is being run directly or it's being imported somewhere else, so when you play your script directly, it will run "main()" because you're doing it directly from the script file. I don't know the exact meanings of name and main but I know how it works
@AScholarsVlog
@AScholarsVlog 5 ай бұрын
You did really good. I like how you specified selecting randint from the random module so it doesn't cause much storage used. Nice work!
@jayanthkadlur99
@jayanthkadlur99 4 ай бұрын
from random import randint def main(): while True: print('*****************GUESS-THE-NUMBER*****************') 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 += 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() THis is the correct version of your code
@TRYING-NOT-TO-OFFEND-YOU
@TRYING-NOT-TO-OFFEND-YOU 5 ай бұрын
skibidi
@শখেরবাড়ি৯৯০
@শখেরবাড়ি৯৯০ 5 ай бұрын
Pakat video cah you also maké a video on python genarators and sqlite please i am 12 years old
@JustNars
@JustNars 5 ай бұрын
here's my Number guessing game! import random random_limit = random.randint(5, 10) print("Welcome to the Python Number Guessing Game! Here you have to GUESS a random number!") print("And you have a random amount of trys Good luck! =====================") print("(-----Difficulty-----) 1)Easy mode [1 - 20] 2)Medium mode [1 - 50 3)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 = int(input("=============== Guess 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 ♥
Functions in Python are easy 📞
10:38
Bro Code
Рет қаралды 610 М.
ROCK PAPER SCISSORS game in Python 🗿
9:29
Bro Code
Рет қаралды 143 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 298 М.
Python lists, sets, and tuples explained 🍍
15:06
Bro Code
Рет қаралды 339 М.
2023 number guessing game description
4:32
Rod Milstead
Рет қаралды 176
Nature's Incredible ROTATING MOTOR (It’s Electric!) - Smarter Every Day 300
29:37
God-Tier Developer Roadmap
16:42
Fireship
Рет қаралды 7 МЛН
How I Would Learn Python FAST in 2024 (if I could start over)
12:19
Thu Vu data analytics
Рет қаралды 648 М.
Learn Python Object Oriented Programming! 🚗
12:18
Bro Code
Рет қаралды 34 М.
Running "Hello World!" in 10 FORBIDDEN Programming Languages
18:07
How NVIDIA just beat every other tech company
9:20
Mrwhosetheboss
Рет қаралды 2 МЛН
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,3 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19