Guess Number Game in Python

Python
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
>>> 


Tags: python,game,number,python game,number guessing game python,guess,number guessing game,python (programming language),guess the number python,python number guessing game,python tutorial,python 3,guess number game,guess the number game,guess a number between 1 and 100 python,game in python,random number guessing game,guessing game,making a game in python,programming,games in pythom,python guessing game

Post a Comment

Previous Post Next Post