Total gaming python multiplayer gaming project - codebugfree

In this section we learn the python basic project. The name of this project is total gaming python multiplayer gaming  project. In this project we need total player is 2. 2 player is play this game.

Python total gaming python multiplayer

The total gaming multiplayer project is also known as number guessing game. The 2 player is input a number and computer generate the random number. Player find the random number.

When two player find the number than compare 2 player and finding the winner and runner up. In this project we use random module to generate the random number. 

Project of total gaming 

import random #import
computer_number = random.randint(1,1000)# generatye the random number
player1_name = input("Player 1 Enter your name: ")
print("You have only 15 chance to guess the number")
player2_name = input("player 2 Enter your name: ")
i = 0
print(f"{player1_name} turn")
while (True):
    i += 1#increment i
    player_number = int(input("Enter your number: "))#input number from user 1
    if player_number == computer_number:
        print("You guess the perfect number")
        break
    else:
        if player_number > computer_number:
            print("You guess high number please choose low")
        else:
            print("you chose low number please choose high")
        if i == 15:
            print(f"sorry you use 15 chance {player2_name}")
            break   
j = 0
computer_number = random.randint(1,1000)#generate the random numnber
print(f"{player2_name} turn")
while (True):
    j += 1
    player2_number = int(input("Enter your number: "))#input number
    if player2_number == computer_number:
        print("You guess the perfect number")
        break#exit loop ehwn guess the number
    else:
        if player2_number > computer_number:
            print("You guess high number please choose low")
        else:
            print("you chose low number please choose high")
        if j == 15:
            print(f"sorry you use 15 chance {player2_name} ")
            break   

   
if i>j:
    print(f"Winner is {player1_name}")#compare two player
else:
    print(f"winner is {player2_name}")

First import the random module. Computer number generate the random number and not print random number. Input player1 and player2 name. starting while loop.

Get number from player1 or player2. matching random number. if number from player 1 and player2 than gives hint please choose low number you choose. if player1 or player 2 is does not guess number with in 15 chance. Than they does not input again number.

At last two player playing is compare and print the winner and runner up of two player

INOUTPUT

Player 1 Enter your name: total gaming
You have only 15 chance to guess the number
player 2 Enter your name: total game
total gaming turn
Enter your number: 500
You guess high number please choose low
Enter your number: 250
you chose low number please choose high
Enter your number: 355
you chose low number please choose high
Enter your number: 380
You guess high number please choose low
Enter your number: 475
You guess high number please choose low
Enter your number: 360
You guess high number please choose low
Enter your number: 355
you chose low number please choose high
Enter your number: 358
You guess high number please choose low
Enter your number: 357
You guess high number please choose low
Enter your number: 356
You guess the perfect number
total game turn
Enter your number: 400
you chose low number please choose high
Enter your number: 800
You guess high number please choose low
Enter your number: 600
you chose low number please choose high
Enter your number: 700
You guess high number please choose low
Enter your number: 650 
You guess high number please choose low
Enter your number: 625
you chose low number please choose high
Enter your number: 635
you chose low number please choose high
Enter your number: 645
You guess high number please choose low
Enter your number: 640
You guess the perfect number
Winner is total gaming

Post a Comment

0 Comments