write this python program 5. Random walk. You may know that the streets and aven
ID: 3602044 • Letter: W
Question
write this python program
Explanation / Answer
import math
def manhattan(row, column):
a = [[0] * column for i in range(row)]
x = math.ceil(row/2)-1
y = math.ceil(column/2)-1
for i in range(y, column):
a[x][i] = a[x][i] + 1
a[x][column-2] = a[x][column-2] + 1
a[x][column-1] = a[x][column-1] + 1
for row in a:
print(' '.join([str(elem) for elem in row]))
manhattan(5, 11)
As per the sample output, I am staring from the center of the grid and travelling to right.
Output:
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 2 2
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.