0% found this document useful (0 votes)
88 views2 pages

Basic Guessing Game - Jupyter Notebook

This document describes a basic number guessing game program written in Python. The program randomly selects a number between 1-9 and allows the user to guess the number within 5 attempts. It provides feedback on whether guesses are too high or too low. If the user guesses correctly within 5 attempts, they win. Otherwise, they lose and the correct number is revealed.

Uploaded by

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

Basic Guessing Game - Jupyter Notebook

This document describes a basic number guessing game program written in Python. The program randomly selects a number between 1-9 and allows the user to guess the number within 5 attempts. It provides feedback on whether guesses are too high or too low. If the user guesses correctly within 5 attempts, they win. Otherwise, they lose and the correct number is revealed.

Uploaded by

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

11/5/2020 Basic Guessing Game - Jupyter Notebook

In [ ]:

import random
print("Number Guessing Game")
number = random.randint(1,9)
chances = 0
print("Guess a number between 1 to 9 :")
while chances<5:
guess = int(input())
if guess == number:
print("You Won")
elif guess<number:
print("Too Low,guess again",guess)
else:
print("Too High,guess again",guess)
chances+=1
if not chances < 5:
print("YOU LOSE!!! The number is", number)

Number Guessing Game


Guess a number between 1 to 9 :
4
Too Low,guess again 4
7
You Won

localhost:8888/notebooks/Downloads/Basic Guessing Game.ipynb 1/2


11/5/2020 Basic Guessing Game - Jupyter Notebook

In [6]:

import random
print("Number guessing game")
number = random.randint(1, 9)
chances = 0
print("Guess a number (between 1 and 9):")
while chances < 5:
guess = int(input())
if guess == number:
print("Congratulation YOU WON!!!")
break

elif guess < number:


print("Your guess was too low: Guess a number higher than", guess)

else:
print("Your guess was too high: Guess a number lower than", guess)

chances += 1

if not chances < 5:


print("YOU LOSE!!! The number is", number)

Number guessing game


Guess a number (between 1 and 9):
8
Your guess was too high: Guess a number lower than 8
4
Your guess was too high: Guess a number lower than 4
3
Your guess was too high: Guess a number lower than 3
2
Congratulation YOU WON!!!

In [ ]:

localhost:8888/notebooks/Downloads/Basic Guessing Game.ipynb 2/2

You might also like