Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python program that simulates playing Bingo. In Bingo, each player has a

ID: 3573320 • Letter: W

Question

Write a Python program that simulates playing Bingo. In Bingo, each player has a card of numbers arranged in a 5×5 grid with five randomly-chosen numbers from 1 to 15 in the B column, 16 to 30 in the I column, 31 to 45 in the N column, 46 to 60 in the G column, and 61 to 75 in the O column. The central space is “free" and is considered occupied. The 24 numbers on a Bingo card are unique.

A caller randomly calls numbers from 1 to 75 without replacement, each player marking the corresponding number, if it is present on their card, as occupied. The first player to have five occupied numbers in a row horizontally, in a column vertically, or along either of the two major diagonals is the winner. How to represent a Bingo card in Python. A dictionary will be used to represent a Bingo card. Here, the keys are the letters B, I, N, G, and O and the value for each key is a list of five integers.

Your job is to write the three functions (check_bingo(), generate_random_card(), simulate_bingo()) described below. If you want to use additional user-defined functions in your program, please do so.

a) Write the check_bingo(card) function. Here, card is a Bingo card represented as a dictionary as described on the previous page. Your code will return True if card has Bingo. Otherwise, it will return False.

b) Write the generate_random_card() function. You will write code to randomly generate a Bingo card. Your Bingo card must be represented as a dictionary as described earlier (also see comments in code). Your code will return a dictionary that represents a valid Bingo card. Example #2 tests your generate_random_card() function. When writing your function, you might find the random.shuffle() command for lists helpful.

c) Write the simulate_bingo(n,k) function. Complete this function to simulate k games (or trials) of Bingo, where n cards (or players) are active in the simulation. Your function will return three values: the minimum, maximum, and average number of calls required to get Bingo among the k games of n cards. For example, if n = 10 and k = 100, then your simulation would report results for playing Bingo 100 times among 10 players. Remember, for each of the k games, you should generate a new set of Bingo cards. To complete the code for this function, make sure to make use of the previous code in parts (a) and (b) that you have written.

d) Note. The main(), print_card(), and open_file_command() have been written for you. These functions drive the program, prints a Bingo card stored in a dictionary, and reads a Bingo card from a file, respectively

card t'B' C7,15,11 2,10], 'I' [25,22,30, 28, 27]N 'N': C44,40,0,37,39], 'G' [57,50,46,55,59] V '0' [62,70,74,68,75]

Explanation / Answer

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 6 17:30:25 2016

@author: naresh
"""
import csv
card = {'B':[7,15,11,2,10],'I':[25,22,30,28,27],'N':[44,40,0,37,39],'G':[57,50,46,55,59],'O':[62,70,74,68,75]}
if __name__ == "__main__":
def open_file_command():
print("for file operations")
li=[]
with open('/home/naresh/Desktop/chegg/card.txt','r') as csvfile:
csvreader = csv.reader(csvfile)
for line in csvreader:
print(line)
li.append(list(line))
print("li",li)
def print_card():
print(card.items())
def check_bingo(card):
print("in checking the bingo game")
def generate_random_card():
import random
# import colle
card = {'B':[],'I':[],'N':[],'G':[],'O':[]}
nums = list(range(75))
random.shuffle(nums)
for val in nums:
if val > 1 and val <= 15:
if val not in card['B']:
if len(card['B']) <= 5:
card['B'].append(val)
elif val > 15 and val <= 30:
if val not in card['I']:
if len(card['I']) <= 5:
card['I'].append(val)
elif val > 30 and val <= 45:
if val not in card['N']:
if len(card['N']) <= 5:
card['N'].append(val)
elif val > 45 and val <= 60:
if val not in card['G']:
if len(card['G']) <= 5:
card['G'].append(val)
elif val > 60 and val <= 75:
if val not in card['O']:
if len(card['O']) <= 5:
card['O'].append(val)   
print(card)
# print(B)
# gridSize = 5
# minNum = 1
# maxNum = 50
# for h in range(5):
# card = []
# randRange = range(minNum, maxNum)
# card = random.sample(randRange, gridSize * gridSize)
# for i in range(gridSize):
# string = ""
# for j in range(gridSize):
# string += str(card[i + j * gridSize]) + " "
# print(string)   
# print(" ")
# print("generate a random card")
def simulate_bingo():
print("simulating bingo game")
generate_random_card();
  
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote