I'd like to ask you a question after making Python multiplication tables.

Asked 2 years ago, Updated 2 years ago, 14 views

I was trying to solve this kind of problem, and I filled in the blanks with that thought.

But I don't know what to fill the matrix and append to print the multiplication tables as in the example.ㅠ<

Help a beginner <

python

2022-09-20 22:17

1 Answers

# Correct answer required by the body
def print_gugudan():
    matrix = []
    for row in range(2, 10):
        matrix.append([])
        for column in range(1, 10):
            matrix[row - 2].append(row * column)
    print(matrix)

I had to organize it according to the template in the question, but it's a little awkward for me to search for an array by designating an index directly like row-2.

I feel comfortable squeezing it like below.

def print_gugudan():
    matrix = []
    for row in range(2, 10):
        result = []
        for column in range(1, 10):
            result.append(row * column)
        matrix.append(result)
    print(matrix)


2022-09-20 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.