# 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}")
@yasjudankhan9 күн бұрын
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)
@anwu21965 ай бұрын
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-he3rn5 ай бұрын
This more intersting and helpful for beginers
@Takiplay2435 ай бұрын
Shout out to you for making free videos that help us
@karth8855 ай бұрын
Nice teaching
@nathanielhale57265 ай бұрын
Could you do an intermediate level Pygame tutorial where you make this same game using labels, buttons, and and input line?
@Reymax1645 ай бұрын
*_Bro actually uploads this frequent?_*
@mamunmondal-he3rn5 ай бұрын
He is my teacher through youtube
@zivb20105 ай бұрын
please make a unity tutorial🥺🙏
@AyushSinhx4 ай бұрын
thanks
@jomon-bq8hz3 ай бұрын
number = random.randint(low, high) ^^^^^^^^^^^^^^ why this happens
@yazant52415 ай бұрын
Can you teach us unity please ❤❤❤❤
@spectrogames85 ай бұрын
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?
@JustNars5 ай бұрын
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
@TheLoneRoninYT5 ай бұрын
What does if main == name mean
@fabiotucci30295 ай бұрын
@@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
@AScholarsVlog5 ай бұрын
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!
@jayanthkadlur994 ай бұрын
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-YOU5 ай бұрын
skibidi
@শখেরবাড়ি৯৯০5 ай бұрын
Pakat video cah you also maké a video on python genarators and sqlite please i am 12 years old
@JustNars5 ай бұрын
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 ♥