Python is very flexible and common high level programming language. Its popularity is increasing day by day. It is mainly used in Data science and Artificial Intelligence.

Here we are going to make a game. In this game, our program will generate random numbers from 0 to 100 (You can change the range whatever your like). There will be two players playing this game. At first One will guess the number. If it is correct then S/he wins, otherwise our program will show that his/her guess is lower or higher than the actual number. And the turn of other player will come and same process is repeated until any one of the player didn’t guess the right number.

After the correct Guess the program will show the name of Winner player and his attempts to solve that problem.

You can change this game in any way you like. That’s why Python is Called flexible language. Isn’t it cool…?

Here is our Program:

player_one=input("Enter first Player\'s Name: ")
player_two=input("Enter Second Player\'s Name: ")
import random
winning_number=random.randint(1,100) #Change these numbers to change #range
guess=1
game_state=False
while not game_state:
    print(f"{player_one}\'s turn: ")
    guess_number=input("Guess any number between 1 and 100: ")
    guess_number=int(guess_number)
    if guess_number==winning_number:
        print(f"{player_one} Won!!! {player_one} guessed right number in {guess} times")
        game_state=True 
    else:
        if guess_number>winning_number:
            print("Too High")
        else:
            print("Too Low")
        print(f"{player_two}\'s turn:'")
        guess_number=int(input("Guess any number between 1 and 100: "))
        if guess_number==winning_number:
            print(f"{player_two} Won!!! {player_two} guessed right number in {guess} times")
            game_state=True
        else:
            if guess_number>winning_number:
                print("Too High")
            else:
                print("Too Low")
        guess+=1
        continue

Here is our Output…

Isn’t it Cool!!Well Thank me later!! Just chill!! that’s how the world works and coding too…😃

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s