Question
Python Code required: For test case, refer to: https://drive.google.com/file/d/13aiAZ5LKTqsf4l2T-j_OMjR4wPddOlK2/view?usp=sharing # Randomly fills an array of size 10x10 with True and False, # displayed as 1
Python Code required:
For test case, refer to: https://drive.google.com/file/d/13aiAZ5LKTqsf4l2T-j_OMjR4wPddOlK2/view?usp=sharing
# Randomly fills an array of size 10x10 with True and False,
# displayed as 1 and 0, and outputs the number of chess knights
# needed to jump from 1s to 1s and visit all 1s (they can jump back
# to locations previously visited).
from random import seed, randrange
import sys
dim = 10
def display_grid():
for row in grid:
print('', ' '.join(str(int(e)) for e in row))
try:
for_seed, n = (int(i) for i in input('Enter two integers: ').split())
if not n:
n = 1
except ValueError:
print('Incorrect input, giving up.')
sys.exit()
seed(for_seed)
if n > 0:
grid = [[randrange(n) > 0 for _ in range(dim)] for _ in range(dim)]
else:
grid = [[randrange(-n) == 0 for _ in range(dim)] for _ in range(dim)]
print('Here is the grid that has been generated:')
display_grid()
# INSERT YOUR CODE HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started