Robotics & Artificial Intelligence

Write a Python program that performs operations on a list of integers. Your program should do the following:

  1. Create a list of integers: [2, 4, 6, 9, 5]
  2. Check and print even numbers.
  3. Check and print odd numbers.

Python List Manipulation

2 Likes

Answer

numbers = [2, 4, 6, 9, 5]

print("Even numbers:")
for n in numbers:
    if n % 2 == 0:
        print(n)

print("Odd numbers:")
for n in numbers:
    if n % 2 != 0:
        print(n)

Output

Even numbers:
2
4
6
Odd numbers:
9
5

Answered By

1 Like


Related Questions