Answer the question
In order to leave comments, you need to log in
Build a table using loops in Python. How to make a sequence?
Good day.
Guys, help me figure out how to build a "table" at least a hint.
It is necessary to build using cycles:
0 2 4 6 8 10
1 3 5 7 9 11
2 4 6 8 10 12
3 5 7 9 11 13
4 6 8 10 12 14
5 7 9 11 13 15
The sequence is approximately clear - as if each subsequent the column increases by 2.
If you write something like:
size = int(input("Enter table size: "))
for col in range(size):
for row in range(size):
if row % 2 == 0:
print (col, end = " ")
else:
print(col + 2, end = " ")
print()
results in:
2 4 2 4 2
3 5 3 5 3
4 6 4 6 4
The first 2 columns of norms, and then they are repeated.
I would be grateful for at least a hint, I'm missing something obvious.
Answer the question
In order to leave comments, you need to log in
You have understood the general meaning correctly. Read a lot about REST and don't forget about security
In python, you can set the loop to work manually.
for i in range(2, 11, 2):
print(i)
size = int(input("Table size: "))
for i in range(size):
for j in range(0, 2*size, 2):
print(i + j, end=' ')
print('\n')
# Второй вариант
for i in range(size):
for j in range(i, 2*size + i, 2):
print(j, end=' ')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question