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