Python Game
Python Game
On
Name Registration no
Akshara Rana
Primarily I would like to thank God for being able to learn a new technology.
Then I would like to express my special thanks of gratitude to the teacher who
provide me the golden opportunity to learn a new technology from home.
I would like to also thank my own college Lovely Professional University for
offering such a course which not only improve my programming skill but also
taught me other new technology.
Then, I would like to thank my parents and friends who have helped me with
their valuable suggestions and guidance for choosing this course.
I am making this project not only for marks but to also increase my knowledge.
THANKS AGAIN TO ALL
The task is to create a script that generates a random number between
a fixed range, and if the user guesses the number right in three
chances, then user wins otherwise user lose.
This game user can play as many numbers of times and whenever
user wins a score is to be given to the user.
At the end the users score must be displayed on the screen.
Hint: Make use of random module to design the game
Abstract steps:
• The user enters the lower and upper bounds of the range.
• As a result, the compiler generates a random integer between the
range and stores it in a variable for future use.
• A while loop will be created for repetitive guessing.
• When a user guesses a number that is greater than a randomly
selected number, the user receives the message “have one more try”.
Your guess was too high.
• If the user guesses a number smaller than a randomly selected
number, the user gets an output of “have one more try “. Your guess
was too small”
• In addition, if the user guesses within a minimum number of
attempts, they get a “Congrat’s” message and also get the winning
scores.
• If the user fails to guess the integer in the minimum number of
guesses, he/she will receive a “Better Luck Next Time!
(Student is free to decide the input and output layout for this mini
project)
Source Code:
import random
print('Guessing game')
co=int(input("How many times you want to play: "))
score=0
for i in range(co):
print(f'Chance number {i+1}')
a=int(input("Enter the lower boundary: "))
b=int(input("Enter the upper boundary: "))
c=random.randint(a,b)
guess=None
no_guess=0
limit=3
while no_guess<limit:
guess = int(input(f'Enter a number between {a} and {b}: '))
no_guess+=1
if guess==c:
print("Congo")
score+=1
break
else:
print("try again")
print(f'Your total score is {score} out of {co}')
Output: