Python Project for beginners #7| Guess The Number -Complete Code | Python for Beginners #lec80

preview_player
Показать описание
In this video we will make a Game Project in Python named "Guess The Number" using functions.

*********************************************

Connect & Contact Me:

*******************************************

More Playlists:

#projects #pythonprojects #python #pythonprogramming #jennyslectures
Рекомендации по теме
Комментарии
Автор

import random

num = random.randint(1, 50)
diff_level=input("Enter the level of difficulty...Type 'easy' or 'hard': ")

if diff_level == "easy":
attempts = 10
print(f"Yor have {attempts} attempts to guess the number!")

elif diff_level == "hard":
attempts = 5
print(f"Yor have {attempts} attempts to guess the number!")

else:
print("Enter valid input!")

while (diff_level == "easy" and attempts > 0) or (diff_level == "hard" and attempts > 0):
guess = int(input("Make a guess: "))

if attempts == 0:
print("You lost")

elif guess<num:
print("Your guess is too low!")
attempts-=1

elif guess>num:
print("Your guess is too high!")
attempts-=1

else:
print("Your guess is correct...You won!")
break

vaishnavisharma
Автор

Thank you so much for sharing knowledge ❤

vasanthkumar
Автор

This code is easy one...
import random
import logo_art
def no_guesses(attempts, i):
if attempts - i != 0:
print('guess again')
return (f"you have {attempts - i} attempts remaining to guesses the number")
else:
return ('you are out of guesses, you lose!!')
def easy_hard(choose_num, attempts):
print(f"you have {attempts} attempts remaining to guess the number!")
for i in range(1, attempts + 1):
guess = int(input('make a guess'))
if guess > choose_num:
print('your guess is too high')
print(no_guesses(attempts, i))
elif guess < choose_num:
print('your guess is too low')
print(no_guesses(attempts, i))
else:
print(f'you guess is right...The answer was {choose_num}')
break
print(logo_art.logo)
print('let me think of a number between 1 to 50.')
num_list = list(range(51))
choose_num = random.choice(num_list)
while True:
level = input("Choose level of difficulty...Type 'easy' or 'hard' : ")
if level == 'easy':
easy_hard(choose_num, attempts = 10)
break
elif level == 'hard':
easy_hard(choose_num, attempts = 5)
break
else:
print("you've entered wrong input, Try again")

Shantanu_lrnr
Автор

import random
level=input("type 'easy' or 'hard' to choose the level: ").lower()
if level=="easy":
print("you have 10 attempts to guess the number between 1 to 50")
attempts=10
elif level=="hard":
print("you have 5 attempts to guess the number between 1 to 50")
attempts=5
else:
print("invalid input")
number=random.randint(1, 50)
print(number)
print(level)
while (level == "easy" and attempts > 0) or (level == "hard" and attempts > 0):
guess=int(input("guess a number: "))
if guess<number:
print("too low")
attempts-=1
print("you have", attempts, "attempts left")
elif guess>number:
print("too high")
attempts-=1
print(f"you have {attempts} attempts left")
else:
print("u guessed it right")
break

bharath-vz
Автор

Jenny Mam, Is there any book you follow for exercises that you make do, can you suggest me any website or book for more real time experience

vinodkumarpunna
Автор

If we entered wrong difficulty to ask again we should call game() in if condition block

shivakrishna_varma
Автор

from random import randint
from L import LOGO
print(LOGO)
print()
print("Think of a number between 1 to 50. ")
while True:
choice = input("Choose difficulty level... type 'easy' or 'hard': ").lower()
options = ['hard', 'easy']
if choice not in options:
print("Enter valid option")
else:
break
if choice == "hard":
count = 5
print(f"you have {count} attempt remaining to guess the number.")
else:
count = 10
print(f"you have {count} attempt remaining to guess the number.")
numbertoguess = randint(30, 40)
counter = False
guess = int(input("Make a guess: "))
while not counter:
if guess < numbertoguess:
print("Your guess is too low \nGuess again")
count = count - 1
print(f"you have {count} attempt left")

elif guess > numbertoguess:
print("Your guess is too high \nGuess again")
count = count - 1
print(f"you have {count} attempt left")
else:
print("Your guess is right... You win")
print(f"the number is {numbertoguess}")
break
if count == 0:
counter = True
print("You are out of guesses")
break
else:
guess = int(input("Make a guess: "))

chinenyeumeaku
Автор

i did this but it was too simple... even these beginner projects are too hard for me

lolabunny
Автор

i also learned python drom this channel

pythonassignment
Автор

Jenny makes me really sad to see that you don't post c++ as often... it would be so helpful to have the oop explained by someone as knowledge as you. don't think much about the views, maybe python gives a little bit more but someone that follows you would benefit much more with c++ because it can follow the c, c++ path, and then python. in the long run the views are gonna be the same or even more, but your channel becomes an even better reference given that it as all the foundational base. thank you so much, God bless you

eumm
Автор

import random
print("guess the number")
computer_guessed=random.randint(1, 50)
difficulty_level=input("enter a difficulty level 'hard' or 'easy':")
if difficulty_level=="easy":
print("you have 10 chances")
for i in range(1, 10):
a no"))
if
print("you are correct")
break
elif
print("your guess is more")
elif
print("your guess is low")
print(f"try again {9-i}")
elif difficulty_level=="hard":
print("you have 5 chances")
for i in range(1, 6):
a no"))
if
print("you are correct")
break
elif human_guessed_number > computer_guessed:
print("your guess is more")
elif human_guessed_number < computer_guessed:
print("your guess is low")
else:
print(f"try again {4-i}")

DARK_RYZEN
Автор

Mam will you upload the c++ programming please post that mam❤😮

Lekshmi_sree
Автор

Ma'am when this python course will complete

puneethreddymreddy
Автор

Major steps involved in the code:

Import the necessary modules: random and logo_art.
Define constants for the number of attempts allowed for each difficulty level.
Define a function set_difficulty that takes the chosen level (‘easy’ or ‘hard’) and returns the corresponding number of attempts.
Define a function check_answer that compares the guessed number with the answer and provides feedback (too low, too high, or correct).
Define the main game function game:
Display a logo.
Generate a random number between 1 and 50 as the answer.
Ask the user to choose a difficulty level.
Set the number of attempts based on the chosen level.
Repeatedly prompt the user to guess a number:
Display the remaining attempts.
Check if the guessed number is correct or not.
Update the remaining attempts.
End the game if the user guesses correctly or runs out of attempts.

muneebbolo
Автор

"""Guess the no"""
import random
print("guess the no")
randomno=random.randint(1, 30)
print(randomno)

level=1
user_level=input("which level you want easy/hard")
chances = 10
hard_chance=5

def diffrence(a, b):
newone=range(a, b)
if len(newone)>=1 and len(newone)<=10:
print("your guessing no is in you near")
elif len(newone)>11 and len(newone)<=20:
print("your guessing no is too high")
elif len(newone) > 21 and len(newone) <= 29:
print("your guessing no is too too high")
else:
print("your trying no is crossing the limit")


while level<10:
if user_level=="easy":
user_input=int(input("find the corect no"))
if user_input == randomno:
print(f"You won this game and your guessing {user_input} no and prection {randomno}are both same")

level = 10
elif chances == 0:
print(f"you Lose this Game Because you dont have{chances} to continue")
diffrence(user_input, randomno)
level = 10

elif user_input !=randomno:
chances-=1
diffrence(user_input, randomno)
print(f"you have only {chances} chances try to guess corect no")
elif user_level=="hard":
user_input = int(input("find the corect no"))
if user_input == randomno:
print(f"You won this game and your guessing {user_input} no and prection {randomno}are both same")
level=10
elif hard_chance==0:
print(f"you Lose this Game Because you dont have{chances} to continue")
diffrence(user_input, randomno)
level = 10
elif user_input != randomno:
hard_chance -= 1
diffrence(user_input, randomno)
print(f"you have only {chances} chances try to guess corect no")







i tried this before watching this vidio through your befoe classes

iam-irfan
Автор

import random

def guess_the_number_game():
print("Choose level of difficulty... Type 'easy' or 'hard':")
level = input().lower()

# Set number of attempts based on difficulty level
attempts = 10 if level == 'easy' else 5
number = random.randint(1, 100) # Random number between 1 and 50

print(f"You have {attempts} attempts remaining to guess the number!")

while attempts > 0:
guess = int(input("Make a guess: "))

if guess < number:
print("Your guess is too low.")
elif guess > number:
print("Your guess is too high.")
else:
print(f"Congratulations! You've guessed the number {number} correctly.")
break

attempts -= 1
if attempts > 0:
print(f"Guess again! You have {attempts} attempts remaining.")
else:
print(f"Sorry, you're out of attempts. The correct number was {number}.")

# Run the game
guess_the_number_game()

padalasantosh
Автор

I'm confused... To observe the lesson or to admire your beauty? Thank yewww new mam !

trichyboys
Автор

import random
print("guess the numbers from 1 to 100:" )
answer = random.randint(1, 100)
choose_level = input("choose level of difficulty Type 'easy' or 'hard': ")
if choose_level == 'easy':
print("you have 10 attempts to guess the number:" )
attempts = 10
while attempts>0:
guess_number = int(input(" enter the guess number:"))
if guess_number == answer:
print(f"your guess number {guess_number} is correct you won")
break
elif guess_number < answer:
print("your guess is low:")
attempts = attempts-1
if attempts == 0:
print("you lost")
else:
print(f"guess again and you have {attempts} attempts only")
elif guess_number > answer:
print("your guess is high:")
attempts = attempts-1
if attempts == 0:
print("you lost")
else:
print(f"guess again and you have {attempts} attempts only")

elif choose_level == 'hard':
print("you have 5 attempts to guess the number:")
attempts = 5
while attempts>0:
guess_number = int(input(" enter the guess number:"))
if guess_number == answer:
print(f"your guess number {guess_number} is correct and won")
break
elif guess_number < answer:
print("your guess is low:")
attempts -= 1
if attempts == 0:
print("you lost")
else:
print(f"guess again and you have {attempts} attempts only" )
elif guess_number > answer:
print("your guess is high:")
attempts -= 1
if attempts == 0:
print("you lost")
else:
print(f"guess again and you have {attempts} attempts only" )
else:
print(" you have entered wrong level name and select proper level")

-kunchalaAjay
Автор

import random

attempts = 0
def easy_or_hard():
global attempts
attempts -= 1
user = int(input('Make a guess: '))
while attempts > 0:
if user == comp:
return (f'your guess is right, Number:{comp}')
if user > comp:
print (f'Your guess is too high')
print (f'You have {attempts} attempts Remaining')
return (easy_or_hard())
if user < comp:
print (f'Your guess is too low')
print (f'You have {attempts} attempts Remaining')
return (easy_or_hard())
return (f"You are out of guesses.. You lose\nNumber is {comp}")

comp = random.randrange(1, 51)
print('Welcomes to Guess a Number Game\nLet me think of a number between 1 to 50')
level = input('Choose level of difficulty... Type(easy or hard): ').lower()

if level == 'easy':
attempts = 10
print (f'You have 10 attempts')
print(easy_or_hard())
if level == 'hard':
attempts = 5
print (f'You have 5 attempts')
print(easy_or_hard())

رينشاد_أ
Автор

Guess Number is always changing if we are unable to guess.

srinivasaraovooda