Introduction:
In this Python code, we will be printing all the even numbers in a given sequence. We will use a for loop to iterate through each number and check if it is divisible by 2 (which means it is even). If the number is even, we will print it along with a message indicating that it is an even number.
Code:
#Print even numbers in the given sequence
numbers = [1,2,3,4,5,6,7,8,9,10]
for num in numbers:
if (num % 2) == 0:
print(num,'is an even Number')
Logic:
- The code uses a for loop to iterate through each number in the given sequence.
- Inside the loop, it uses the modulus operator to check if the number is divisible by 2.
- If the remainder is 0, then the number is even, and it is printed along with the message indicating that it is an even number.
Output:
>> 2 is an even Number
>> 4 is an even Number
>> 6 is an even Number
>> 8 is an even Number
>> 10 is an even Number