Course Content
Python Loops Tutorial
Python Loops Tutorial
List & while Loop
We've already integrated lists into for
loops.
To interact with the list now, we'll require one crucial function: len(list)
. This function provides the list's length.
Don't fret; you'll grasp it!
Examine the code below:
numbers = [1, 2, 4, 5, 7] i = 0 # Printing all elements from the list while i < len(numbers): print(numbers[i]) i += 1
How does the code work?
Swipe to show code editor
Calculate the sum of the squares of the numbers in the list.
-
Initialize a
while
loop, usingi
as the index to iterate through thenumbers
. -
Accumulate the squares of the numbers into the
counter
to compute the sum. -
Display the value stored in the
counter
.
Thanks for your feedback!
List & while Loop
We've already integrated lists into for
loops.
To interact with the list now, we'll require one crucial function: len(list)
. This function provides the list's length.
Don't fret; you'll grasp it!
Examine the code below:
numbers = [1, 2, 4, 5, 7] i = 0 # Printing all elements from the list while i < len(numbers): print(numbers[i]) i += 1
How does the code work?
Swipe to show code editor
Calculate the sum of the squares of the numbers in the list.
-
Initialize a
while
loop, usingi
as the index to iterate through thenumbers
. -
Accumulate the squares of the numbers into the
counter
to compute the sum. -
Display the value stored in the
counter
.
Thanks for your feedback!
List & while Loop
We've already integrated lists into for
loops.
To interact with the list now, we'll require one crucial function: len(list)
. This function provides the list's length.
Don't fret; you'll grasp it!
Examine the code below:
numbers = [1, 2, 4, 5, 7] i = 0 # Printing all elements from the list while i < len(numbers): print(numbers[i]) i += 1
How does the code work?
Swipe to show code editor
Calculate the sum of the squares of the numbers in the list.
-
Initialize a
while
loop, usingi
as the index to iterate through thenumbers
. -
Accumulate the squares of the numbers into the
counter
to compute the sum. -
Display the value stored in the
counter
.
Thanks for your feedback!
We've already integrated lists into for
loops.
To interact with the list now, we'll require one crucial function: len(list)
. This function provides the list's length.
Don't fret; you'll grasp it!
Examine the code below:
numbers = [1, 2, 4, 5, 7] i = 0 # Printing all elements from the list while i < len(numbers): print(numbers[i]) i += 1
How does the code work?
Swipe to show code editor
Calculate the sum of the squares of the numbers in the list.
-
Initialize a
while
loop, usingi
as the index to iterate through thenumbers
. -
Accumulate the squares of the numbers into the
counter
to compute the sum. -
Display the value stored in the
counter
.