Conteúdo do Curso
Python Loops Tutorial
Python Loops Tutorial
First Nested Loop Pattern
A nested loop is a loop located within the body of an outer loop. Either the inner or outer loop can take on various forms, including a while
loop or a for
loop. For instance, the outer for
loop can encompass a while
loop, and conversely.
Initially, let's attempt to create a basic image using a nested loop.
Employ end = ' '
within the print function to display elements in a row.
Examine the code below:
# Printing a triangle # Outer for loop for i in range(1, 5): # Inner for loop for j in range(1, i + 1): print('*', end=' ') print('')
How does the code work?
Tarefa
You should reverse the triangle shown in the example.
- Configure the
range()
function for the outerfor
loop withstep = -1
. - Configure the
range()
function for the innerfor
loop. - Print
'*'
within the nested loop.
Obrigado pelo seu feedback!
First Nested Loop Pattern
A nested loop is a loop located within the body of an outer loop. Either the inner or outer loop can take on various forms, including a while
loop or a for
loop. For instance, the outer for
loop can encompass a while
loop, and conversely.
Initially, let's attempt to create a basic image using a nested loop.
Employ end = ' '
within the print function to display elements in a row.
Examine the code below:
# Printing a triangle # Outer for loop for i in range(1, 5): # Inner for loop for j in range(1, i + 1): print('*', end=' ') print('')
How does the code work?
Tarefa
You should reverse the triangle shown in the example.
- Configure the
range()
function for the outerfor
loop withstep = -1
. - Configure the
range()
function for the innerfor
loop. - Print
'*'
within the nested loop.
Obrigado pelo seu feedback!
First Nested Loop Pattern
A nested loop is a loop located within the body of an outer loop. Either the inner or outer loop can take on various forms, including a while
loop or a for
loop. For instance, the outer for
loop can encompass a while
loop, and conversely.
Initially, let's attempt to create a basic image using a nested loop.
Employ end = ' '
within the print function to display elements in a row.
Examine the code below:
# Printing a triangle # Outer for loop for i in range(1, 5): # Inner for loop for j in range(1, i + 1): print('*', end=' ') print('')
How does the code work?
Tarefa
You should reverse the triangle shown in the example.
- Configure the
range()
function for the outerfor
loop withstep = -1
. - Configure the
range()
function for the innerfor
loop. - Print
'*'
within the nested loop.
Obrigado pelo seu feedback!
A nested loop is a loop located within the body of an outer loop. Either the inner or outer loop can take on various forms, including a while
loop or a for
loop. For instance, the outer for
loop can encompass a while
loop, and conversely.
Initially, let's attempt to create a basic image using a nested loop.
Employ end = ' '
within the print function to display elements in a row.
Examine the code below:
# Printing a triangle # Outer for loop for i in range(1, 5): # Inner for loop for j in range(1, i + 1): print('*', end=' ') print('')
How does the code work?
Tarefa
You should reverse the triangle shown in the example.
- Configure the
range()
function for the outerfor
loop withstep = -1
. - Configure the
range()
function for the innerfor
loop. - Print
'*'
within the nested loop.