Skip to main content

Guess The Number - Game (only code)

This project is of a game, which is made with python codes.
This game is limited to only 5 moves , and the target is between 1 - 10.

HOW TO RUN THIS CODE:-

Download any python running IDE to run this code.

HERE's THE CODE :-

# First Python Game

# Python Game

# Guess The Number

import random

opop = (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10)

yours = random.choice(opop)

print("\n\t\t\tWELCOME TO GUESS THE NUMBER GAME.")

print("\t\t\tYOUR TARGET IS BETWEEN 1-10")

print("TOTAL NO. OF GUESSES IS 5" , end = "")

i = 1

while(i<=5) :

    yg = int(input("\nENTER YOUR GUESS\n==> "))

    if(yg<yours and yg<11) :

        print("YOUR GUESS IS LESS" , f"                                                         REMAINING GUESSES = {5-i}")

    elif(yg>yours and yg<11) :

        print("YOUR GUESS IS MORE" , f"                                                         REMAINING GUESSES = {5-i}")

    else :

        print("\nYOU WON THIS GAME")

        print(f"NUMBER OF GUESSES YOU TOOK = {i}")

        print(f"THE ANSWER WAS {yours}\n")    

        break

    i+=1

if(i>5) :

    print("\nSORRY! NUMBER OF GUESSES ARE EXEDED")

    print(f"THE ANSWER WAS {yours}")


a = input("IF YOU WANT TO CONTINUE THEN PRESS 'y' OTHERWISE PRESS ANYTHING TO LEAVE.\n==> ")

def blog() :

    yours = random.choice(opop)

    print("\n\t\t\tWELCOME TO GUESS THE NUMBER GAME.")

    print("\t\t\tYOUR TARGET IS BETWEEN 1-10")

    print("TOTAL NO. OF GUESSES IS 5" , end = "")

    i = 1

    while(i<=5) :

        yg = int(input("\nENTER YOUR GUESS\n==> "))

        if(yg<yours and yg<11) :

            print("YOUR GUESS IS LESS" , f"                                                         REMAINING GUESSES = {5-i}")

        elif(yg>yours and yg<11) :

            print("YOUR GUESS IS MORE" , f"                                                         REMAINING GUESSES = {5-i}")

        else :

            print("\nYOU WON THIS GAME")

            print(f"NUMBER OF GUESSES YOU TOOK = {i}")

            print(f"THE ANSWER WAS {yours}")    

            break

        i+=1

    if(i>5) :

        print("\nSORRY! NUMBER OF GUESSES ARE EXEDED")

        print(f"THE ANSWER WAS {yours}\n")


if(a != "y") :

    print('THANKS FOR PLAYING MY GAME.')

while(a == "y") :

    blog()

    a = input("IF YOU WANT TO CONTINUE THEN PRESS 'y' OTHERWISE PRESS ANYTHING TO LEAVE.\n==> ")

    if(a != "y") :

        print('THANKS FOR PLAYING MY GAME.')

    else :

        continue

Comments

Popular posts from this blog

Stone, Paper and Scissor - Game (only code)

Python Bill Generator (only code)

SPACE WAR - GAME