Answer the question
In order to leave comments, you need to log in
Learning Python, embarrassing but need help. Can you help?
Good day to all. I am going through Python training, I was faced with the task of taking 4 numbers from 1 to 10 from the user and making a multiplication table out of them. Something like this:
Where: 5 and 6 are numbers in the range c, d And 7, 8, 9, 10 are numbers in the
range
a, b
it says 5 days only and the task is to do it only with a for loop and a range operator.
I threw in the code, it displays the formatting correctly, but such a bastard multiplies only by the last digits :(
Here is the code:
for i in range(c, d + 1):
print('\t', i, end='')
print()
for j in range(a, b + 1):
print(j, '\t', i * j)
Answer the question
In order to leave comments, you need to log in
Well, you need to multiply EVERY number from the first range (c, d+1) by EVERY number from the second range (a, b+1) in the second loop. Those. you need nested loops.
More or less like this:
for j in range(a, b + 1):
# здесь выводим значение из диапазона
print (j, '\t', end = '')
for i in range(c, d + 1):
# здесь считаем значения для каждой комбинации
print( i * j, '\t', end = '')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question