for x in range(5):
print(x, end=' ')
for y in range(x,4):
print(y, end=' ')
print()
Nested loops
Loops can also be placed inside of loops.
You can visualize this code at http://www.pythontutor.com/visualize.html
What will this print?
Example: matrix creation
= []
mat = int(input("Enter the number of lines: "))
lines = int(input("Enter the number of columns: "))
cols for i in range(cols):
= []
line for j in range(lines):
= float(input(f"Enter the number at line {i} and col {j}: "))
x
line.append(x) mat.append(line)