0% found this document useful (0 votes)
40 views1 page

Guess The Number

The document describes a number guessing game that allows a user to choose a lower and upper limit for a random number. It then generates a random number within those limits and prompts the user to guess the number, providing hints if their guess is too high or low. The user has 8 attempts to guess correctly before the number is revealed.

Uploaded by

saranya ganesan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Guess The Number

The document describes a number guessing game that allows a user to choose a lower and upper limit for a random number. It then generates a random number within those limits and prompts the user to guess the number, providing hints if their guess is too high or low. The user has 8 attempts to guess correctly before the number is revealed.

Uploaded by

saranya ganesan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import random

upper_limit = int(input("Enter upper limit: "))

lower_limit = int(input("Enter lower limit: "))

random_numer = random.randint(lower_limit,upper_limit)

print("You will have to choose a number between ",upper_limit,"and",lower_limit)

while True:

import random

lower_limit = int(input("Enter the lower limit: "))

upper_limit = int(input("Enter upper limit: "))

random_number = random.randint(lower_limit, upper_limit)

print("You will have to choose a number between ", upper_limit, " and ", lower_limit)

chances = 0

while chances < 8:

chances += 1

guess = int(input("Enter your guess: "))

if random_number == guess:

print("Congragulations, you did it. The number was ", random_number)

break

elif guess < random_number:

print("You guessed a small number.")

elif guess > random_number:

print("You guessed a large number.")

if chances == 7:

print("\n You've run out of chances")

print("\n The number was ", random_number)

print("Better luck next time")

break

print("\n")

break

You might also like