python project[1]
python project[1]
AIM:
DESCRIPTION:
The game begins by importing the random module, which is used to select
a random number from a specified range.
2. Function Definitions:
no_guesses(attempts, i):
This function checks how many attempts the player has left. If there
are attempts remaining, it prompts the player to guess again and
informs them of the remaining attempts. If no attempts are left, it
indicates that the player has lost the game.
easy_hard(choose_num, attempts):
This function handles the main game logic. It informs the player of
the number of attempts they have and enters a loop where the
player can make guesses.
For each guess, the function checks if the guess is too high, too low,
or correct:
3. Game Loop:
If the player enters an invalid input, they are prompted to try again.
TEAM MEMBERS:
S.PRAVEENA
ROLL NO:2319A0515
K.V.NANDAPRIYA
ROLL NO:23191A0507
KAVYA SHREE
S.PRAVEENA:
Develop the no_guesses and easy_hard functions, ensuring they handle user
input and provide appropriate feedback.
KV NANDAPRIYA:
KAVYA SHREE:
PROGRAM:
import random
def no_guesses(attempts,i):
if attempts - i != 0:
print('guess again')
else:
def easy_hard(choose_num,attempts):
print(no_guesses(attempts,i))
print(no_guesses(attempts,i))
else:
break
num_list = list(range(51))
choose_num = random.choice(num_list)
if level == 'easy':
easy_hard(choose_num,attempts = 10)
break
easy_hard(choose_num,attempts = 5)
break
else:
OUTPUT:
make a guess 45
guess again
make a guess 30
guess again
make a guess 20
guess again
make a guess 26
guess again
make a guess 28
guess again
make a guess 27
CONCLUSION:
The number guessing game project serves as an engaging and educational exercise in
Python programming, allowing participants to apply fundamental concepts such as
loops, conditionals, functions, and user input handling.