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

In Python: Do not use functions!!! Minesweeper Board Create a program that displ

ID: 3600713 • Letter: I

Question

In Python:

Do not use functions!!!

Minesweeper Board Create a program that displays a 5x5 solution board for the game Minesweeper I. Create a 2D list that is 7x7 in size and initialize each location to (Note: Only the center 5x5 part of this list is actually used, the extra border is to make it easier to do the counting) 2. Assign the value X' to five random locations in the center 5x5 board to represent your mines a. randomize both the row and the column 1-5 3. Fill in the remaining locations of the board using nested for loops, iterate through each spot in the 5x5 center portion of the board and count the number of 'X's in the eight surrounding spots a. i. check up, down, left, right, and each of the diagonals ii. the outer part of the 7x7 board makes it so you don't have to do an extra check to make sure you're not going out of bounds of the list. b. place the value of the counter in that spot. c. be careful not to accidently overwrite any 'X's 4. Display the final 5x5 board Example Outputs Minesweeper X 2 2 1 1 2 X 2 X 1 2 2 2 1 1 X 2 11 0 1 2X1 0 Minesweeper 1 XX 1 0 1 3 3 2 0 01 X 2 1 1 222 X 1 X 1 1 1

Explanation / Answer

import random

#-------creating a 2D 7x7 character array with dummy character as 'a'
mineSweeper = [['a']*7 for i in range(7)]
count=0

#-------putting mines at 5 random places.
while(count<5):
#--------generating random integers in the range [1,5]
#--------randint is used to generate integers randomly in a given range.
xindex = random.randint(1,5)
yindex = random.randint(1,5)
if(mineSweeper[xindex][yindex]!='X'):
mineSweeper[xindex][yindex] = 'X'
count += 1
  
for i in range(1,6):
for j in range(1,6):
if(mineSweeper[i][j]!='X'):
count = 0
  
#--------checking all the 8 surrounding spots.
if(mineSweeper[i-1][j-1]=='X'):
count += 1
if(mineSweeper[i-1][j]=='X'):
count += 1
if(mineSweeper[i-1][j+1]=='X'):
count += 1
if(mineSweeper[i][j-1]=='X'):
count += 1
if(mineSweeper[i][j+1]=='X'):
count += 1
if(mineSweeper[i+1][j-1]=='X'):
count += 1
if(mineSweeper[i+1][j]=='X'):
count += 1
if(mineSweeper[i+1][j+1]=='X'):
count += 1
  
#------typecast integer to char.
mineSweeper[i][j] = chr(48+count)
  
#--------printing center 5x5 board
print("Minesweeper")
for i in range(1,6):
for j in range(1,6):
print(mineSweeper[i][j]),
print('')

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