V
V
Viktor2021-07-25 00:55:49
Python
Viktor, 2021-07-25 00:55:49

Error while outputting multiplication table?

I'm ashamed to ask such a stupid question, but I can't figure out how to solve this problem. I'm trying to display the multiplication table using for loops. Here is the code

a, b = 1, 5
x, y = 1, 5

for i in range(x, y):
    # выводит верхнюю последовательность чисел
    print("\t", i, end="")

for j in range(a, b):
    # выводит боковую последовательность чисел
    print()
    for i in range(x, y):
        # последовательности перемножаются
        z = i * j
        print(j, z, sep="\t", end="")
        # print("\t", z, end="")

The following result
60fc8b440978f434222164.png
is displayed. As you can see, extra 1, 2, 3, 4 are put in each column. It dawned on me that it was the j in the line of code: but I still did not understand how to solve this problem. Thank you in advance. print(j, z, sep="\t", end="")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2021-07-25
@Dovahki_in

for i in range(1, 5):
    # выводит верхнюю последовательность чисел
    print("\t", i, end="")

for j in range(1, 5):
    # выводит боковую последовательность чисел
    print()
    F = True
    for i in range(1, 5):
        # последовательности перемножаются
        z = i * j
        if F:print(j, end="")
        print("\t", z, end="")
        F = False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question