Table of Contents
Example Description
Learn how to use the for loop in Python to print a sequence of numbers, understand its logic with step-by-step explanations.

Introduction:

In this Python code example, we will demonstrate how to use a for loop to print a sequence of numbers. The given sequence of numbers is [10, 20, 30, 40, 50]. We will iterate over each number in the sequence using the for loop and print it.

Code:

#Print the given sequence of numbers using for loop
count = [10,20,30,40,50]
for num in count:
 print(num)

Logic:

1. We start by defining a list of numbers called “count” with the values [10, 20, 30, 40, 50].
2. We use a for loop to iterate over each number in the “count” list.
3. On each iteration, the current number is assigned to the variable “num”.
4. We use the “print” function to output the current number.
5. The loop continues until all numbers in the “count” list have been printed.

Output:

>> 10

>> 20

>> 30

>> 40

>> 50