M
M
Michael Sne Bjorn Palagin2016-04-26 09:20:38
Python
Michael Sne Bjorn Palagin, 2016-04-26 09:20:38

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
a863a2af75a5c1541f4081d101eb8c25.png
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 :(
1d32e06d3494cbdbb0fa7dd05dd430e3.png
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)

I've been breaking my head for a day and I don't understand how to do it :( Maybe someone will say what's wrong :(
I would be very grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nicholas, 2016-04-26
@healqq

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 = '')

F
Fidenas, 2016-04-26
@Fidenas

The for loop is missing, you only iterate over j in the range (a, b+1), another loop should also iterate over the values ​​in the range (c, d+1).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question