You are on page 1of 2

HomeWork: 3

• 1. The Number Guessing Game


In this game the computer chooses a random number between 1 and 100, then the player
and the computer tries to guess the number in as few attempts as possible. Each time the
player enters a guess or the computer enters a guess, the computer tells him whether the
guess is too high, too low, or right. Once the player or the computer guesses the number,
the game is over.
Answer:

import random

guesses = 1
randomNumber = random.randint(1,100)

guess = int(input("Please Enter a number between 1 to 100 : "))

while guess != randomNumber:


if guess < randomNumber :
print("guess number is too loo")
guess = int(input("Please enter a integer again : "))
guesses = guesses+1
elif guess > randomNumber:
print("guess number is too high")
guess = int(input("Please enter a integer again : "))
guesses = guesses + 1
print("Congratulation you win game over")

Screenshot: code with output result

You might also like