0% found this document useful (0 votes)
4 views

Lab Assignment 4 Imp

The document is a lab assignment for a guessing game program developed in Python. It outlines the requirements for the game, which includes generating a random number, prompting the user for guesses, and providing hints until the correct number is guessed. The provided Python code implements these functionalities and prints a congratulatory message upon winning the game.

Uploaded by

abd.shah3669
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)
4 views

Lab Assignment 4 Imp

The document is a lab assignment for a guessing game program developed in Python. It outlines the requirements for the game, which includes generating a random number, prompting the user for guesses, and providing hints until the correct number is guessed. The provided Python code implements these functionalities and prints a congratulatory message upon winning the game.

Uploaded by

abd.shah3669
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/ 4

LAB ASSIGNMENT #04

Applications of ICT
(Information and Communication Technologies)
Instructor: Mr. Mohsin Ahmed

Student Name: Abdullah shah


Registration No: FA24-BSE-093
Department: Software engineering
Submission Date: 30th December 2024

COMSATS University Islamabad


Guessing Game

Develop a Python program that plays a guessing game


with the user. The program should:

- Think of a random number between 1 and 100


- Ask the user to guess the number
- Provide hints (e.g., "Too high" or "Too low") based on
the user's guess
- Repeat the process until the user guesses the correct
number
- Print a congratulatory message when the user win

PYTHON CODE:
print('\nWelcome to the guessing game')
print('You have unlimited chances to guess the number between 1 and 100')
import random
number = random.randint(1,100)
while True:
guess = int(input('Enter your guess: '))
if guess == number:
print('You guessed it right')
print("congratulations")
break
else:
print('Try again')
#Hint
if guess < number:
print('The number is greater than', guess)
else:
print('The number is less than', guess)
print('The number was', number)
print('Game over')

OUTPUT FOR CODE:

You might also like