Open In App

Create Bingo Game Using Python

Last Updated : 08 Jun, 2023
Comments
Improve
Suggest changes
5 Likes
Like
Report

A card with a grid of numbers on it is used to play the popular dice game of bingo. Players check off numbers on their cards when they are selected at random by a caller, competing to be the first to mark off all of their numbers in a particular order. We'll examine how to utilise Python to create a simple bingo game in this lesson.

The following ideas must be understood in order to design a bingo game:

  • Lists: A list is a group of items that can contain any sort of data.
  • Random module: In Python, random numbers are produced using the random package.
  • Loops: Loops are used to repeatedly run a block of code until a predetermined condition is satisfied.
  • Functions: A set of statements that carry out a particular activity are grouped together into functions.

Steps:

  1. Make a list of all potential bingo numbers (1–25).
  2. For a random order of the numbers, mix up the list.
  3. With the centre square denoted as "free," make a bingo card with a 5x5 grid of numbers.
  4. Make a list of 24 distinct bingo cards with various number combinations.
  5. Write a function that draws a number at random from the shuffled list of bingo numbers and checks to see whether any of the numbers on the players' bingo cards match the selected number.
  6. When a player has checked off all the numbers in a certain sequence, keep drawing numbers (e.g., a straight line, a diagonal, or all four corners).

Source Code :

Output:

Bingo Card 1:

1  3  5  4  2

8  7  6  9 10

15 13  0 11 12

16 19 20 17 18

23 21 25 22 24

     

Bingo Card 2:

3  2  4  5  1

10  7  9  6  8

15 11  0 12 13

19 18 20 16 17

22 21 25 24 23

     

New Bingo ball:  10

Press Enter to draw the next Bingo ball...

Bingo Card 1:

1  3  5  4  2

8  7  6  9  X

15 13  0 11 12

16 19 20 17 18

23 21 25 22 24

     

Bingo Card 2:

3  2  4  5  1

X  7  9  6  8

15 11  0 12 13

19 18 20 16 17

22 21 25 24 23

     

New Bingo ball:  11

Press Enter to draw the next Bingo ball...

Bingo Card 1: 

1  3  5  4  2

8  7  6  9  X

15 13  0  X 12

16 19 20 17 18

23 21 25 22 24

     

Bingo Card 2:

3  2  4  5  1

X  7  9  6  8

15  X  0 12 13

19 18 20 16 17

22 21 25 24 23

    

New Bingo ball:  22

Press Enter to draw the next Bingo ball...

Bingo Card 1:

1  3  5  4  2

8  7  6  9  X

15 13  0  X 12

16 19 20 17 18

23 21 25  X 24

     

Bingo Card 2:

3  2  4  5  1

X  7  9  6  8

15  X  0 12 13

19 18 20 16 17

X 21 25 24 23

     

New Bingo ball:  1

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  3  5  4  2

8  7  6  9  X

15 13  0  X 12

16 19 20 17 18

23 21 25  X 24

     

Bingo Card 2:

3  2  4  5  X

X  7  9  6  8

15  X  0 12 13

19 18 20 16 17

X 21 25 24 23

     

New Bingo ball:  9

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  3  5  4  2

8  7  6  X  X

15 13  0  X 12

16 19 20 17 18

23 21 25  X 24

     

Bingo Card 2:

3  2  4  5  X

X  7  X  6  8

15  X  0 12 13

19 18 20 16 17

X 21 25 24 23

     

New Bingo ball:  8

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  3  5  4  2

X  7  6  X  X

15 13  0  X 12

16 19 20 17 18

23 21 25  X 24

     

Bingo Card 2:

3  2  4  5  X

X  7  X  6  X

15  X  0 12 13

19 18 20 16 17

X 21 25 24 23

     

New Bingo ball:  3

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  4  2

X  7  6  X  X

15 13  0  X 12

16 19 20 17 18

23 21 25  X 24

     

Bingo Card 2:

X  2  4  5  X

X  7  X  6  X

15  X  0 12 13

19 18 20 16 17

X 21 25 24 23

    

New Bingo ball:  4

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  7  6  X  X

15 13  0  X 12

16 19 20 17 18

23 21 25  X 24

     

Bingo Card 2:

X  2  X  5  X

X  7  X  6  X

15  X  0 12 13

19 18 20 16 17

X 21 25 24 23

     

New Bingo ball:  18

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  7  6  X  X

15 13  0  X 12

16 19 20 17  X

23 21 25  X 24

     

Bingo Card 2:

X  2  X  5  X

X  7  X  6  X

15  X  0 12 13

19  X 20 16 17

X 21 25 24 23

     

New Bingo ball:  13

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  7  6  X  X

15  X  0  X 12

16 19 20 17  X

23 21 25  X 24

     

Bingo Card 2:

X  2  X  5  X

X  7  X  6  X

15  X  0 12  X

19  X 20 16 17

X 21 25 24 23

    

New Bingo ball:  20

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  7  6  X  X

15  X  0  X 12

16 19  X 17  X

23 21 25  X 24

    

Bingo Card 2:

X  2  X  5  X

X  7  X  6  X

15  X  0 12  X

19  X  X 16 17

X 21 25 24 23

     

New Bingo ball:  7

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  X  6  X  X

15  X  0  X 12

16 19  X 17  X

23 21 25  X 24

     

Bingo Card 2:

X  2  X  5  X

X  X  X  6  X

15  X  0 12  X

19  X  X 16 17

X 21 25 24 23

    

New Bingo ball:  24

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  X  6  X  X

15  X  0  X 12

16 19  X 17  X

23 21 25  X  X

    

Bingo Card 2:

X  2  X  5  X

X  X  X  6  X

15  X  0 12  X

19  X  X 16 17

X 21 25  X 23

    

New Bingo ball:  12

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  X  6  X  X

15  X  0  X  X

16 19  X 17  X

23 21 25  X  X

     

Bingo Card 2:

X  2  X  5  X

X  X  X  6  X

15  X  0  X  X

19  X  X 16 17

X 21 25  X 23

     

New Bingo ball:  6

Press Enter to draw the next Bingo ball...

Bingo Card 1:

X  X  5  X  2

X  X  X  X  X

15  X  0  X  X

16 19  X 17  X

23 21 25  X  X

    

Bingo Card 2:

X  2  X  5  X

X  X  X  X  X

15  X  0  X  X

19  X  X 16 17

X 21 25  X 23

    

New Bingo ball:  25

Bingo! Player 1 wins!


Next Article
Article Tags :
Practice Tags :

Similar Reads