Bingo Game Project

Bingo Game Project

Write a Python code game to play a simplified version of Bingo between two players. The program should generate and display the cards for both players. Each card should consist of 10 numbers arranged in two rows and five columns.

The program will prompt the players to indicate if they want to start the game. If they choose to start, the program will simulate the bingo ball and begin displaying random numbers between 0 and 99, with a 1-second delay between each number. Additionally, the program will ask the players to enter “bingo” if any of the numbers called match at least three numbers on their card.

Once a player enters “bingo,” the program will check if any of the numbers on their card match at least three of the numbers that have been called. Your program should accurately determine the winner and display an appropriate message.

It is a fun Python code game project to practice problem solving skills, functional programming and nested loops.

Steps

  1. Generate and display bingo cards for two players.
  2. Ask the players if they wish to start the game.
  3. With a “while” loop, simulate the bingo ball and display random numbers between 0 and 99 with a 1-second delay.
  4. Ask the users to enter “bingo” if any of the cards has at least three bingo numbers.
  5. Check if any card has at least 3 of the bingo numbers that have been printed.
  6. Declare a winner if any player enters “bingo” and meets the winning criteria.

Expected Output:

Player 1's card:
[61, 29, 21, 42, 91]
[23, 1, 5, 54, 4]

Player 2's card:
[54, 81, 82, 4, 45]
[80, 74, 18, 47, 6]

Do you want to start the game? (yes/no): yes
Bingo number is: 19
Enter 'bingo' if you have it, or press Enter to continue: 
Bingo number is: 34
Enter 'bingo' if you have it, or press Enter to continue: 
Bingo number is: 43
Enter 'bingo' if you have it, or press Enter to continue: 
Bingo number is: 40
Enter 'bingo' if you have it, or press Enter to continue: 
Bingo number is: 41

Source Code



import random
import time

# Step 1: Generate and display bingo cards for two players
def generate_bingo_card():
    numbers = random.sample(range(100), 10)
    card = [numbers[:5], numbers[5:]]
    return card

def display_bingo_card(card):
    for row in card:
        print(row)

player1_card = generate_bingo_card()
player2_card = generate_bingo_card()

print("Player 1's card:")
display_bingo_card(player1_card)

print("\nPlayer 2's card:")
display_bingo_card(player2_card)

# Step 2: Ask if the players wish to start the game
start_game = input("Do you wish to start the game? (yes/no): ")
if start_game.lower() != 'yes':
    exit()

# Step 3: Simulate the bingo ball and ask for "bingo"
bingo_numbers = []
while True:
    called_number = random.randint(0, 99)
    print("The next number is:", called_number)
    time.sleep(1)

    bingo_call = input("Enter 'bingo' if you have a bingo: ")
    if bingo_call.lower() == 'bingo':
        break

    bingo_numbers.append(called_number)

# Step 4: Check for bingo
def check_bingo(card, called_numbers):
    count = 0
    for row in card:
        for number in row:
            if number in called_numbers:
                count += 1
    return count >= 3

# Step 5: Check for winner
if check_bingo(player1_card, bingo_numbers):
    print("Player 1 wins! They have a bingo.")
elif check_bingo(player2_card, bingo_numbers):
    print("Player 2 wins! They have a bingo.")
else:
    print("No winner this time. Better luck next time!")


 

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for Practice
Register New Account
Shopping cart