#๐ not getting desired output
16 messages ยท Page 1 of 1 (latest)
@dire linden
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
def call_of_ones(n):
matrix = [[0] * n for _ in range(n)]
def fill_layer(layer, value=1):
for i in range(layer, n - layer):
matrix[layer][i] = value
for i in range(layer + 1, n - layer):
matrix[i][n - layer - 1] = value
for i in range(n - layer - 2, layer - 1, -1):
matrix[n - layer - 1][i] = value
for i in range(n - layer - 2, layer, -1):
matrix[i][layer] = value
layers = (n + 1) // 2
for layer in range(layers):
fill_layer(layer)
return matrix
n = 5
result = call_of_ones(n)
for row in result:
print(row)
this is my question
Consider an n*n matrix of the following form:
[1 1 1 1 1]
[1 0 0 0 0]
[1 0 1 1 0]
[1 0 0 1 0]
[1 1 1 1 0]
Write a function call_of_ones(n) that produces a n x n matrix of the given form. Make sure that the recursive steps are in the correct order (i.e, the ones go right, then down, then left, then up, then right, etc.)
Uh anyone help?
๐
doesn't it say to use recursion tho
How can I use and get the output
๐ญ
I won't give you an answer you can copy paste
I can help you to the solution tho
Ya I need help
:xdm:
define the function move(matrix, i, j, direction, steps, max_steps)
i, jis where you're at (matrix[i][j])directionis the direction of the last movestepsis how many steps you've taken in the same direction alreadymax_stepsis how many steps you should take before turning again
go from there
Umm
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.