Guess Number Game in Python

Guess Number Game in 
Python


Code:

import random

print("Welcome to the Game")

print("i will pick a number from 1 to 100, you have to guess that number. GOOD LUCK")

a=random.randint(1,100)
nog=0

g=int(input("guess the number : "))
while(g!=a):
    nog+=1
    print("number of Guesses",nog)
    if(g>a):
        print("guess lower number")
        g=int(input("guess the number : "))
    elif(g<a):
        print("guess higher number")
        g=int(input("guess the number : "))
        
print("Congratulations! you guess it right")
print("number of Guesses",nog)
        

        

        




Output:


Welcome to the Game
i will pick a number from 1 to 100, you have to guess that number. GOOD LUCK

guess the number : 10
number of Guesses 1
guess higher number

guess the number : 30
number of Guesses 2
guess higher number

guess the number : 40
number of Guesses 3
guess higher number

guess the number : 80
number of Guesses 4
guess higher number

guess the number : 90
number of Guesses 5
guess lower number

guess the number : 85
number of Guesses 6
guess higher number

guess the number : 86
Congratulations! you guess it right
number of Guesses 6
>>> 

Video Tutorial:




No comments:

Powered by Blogger.