As a newbie programmer

Divide The Array @ Dcoder

Dcoder icon

Problem: Cody loves even numbers. He was bored and decided to print all the even numbers at the even indexes of an array(1-indexed). He wants your help to complete this task.

Input: The first line of the input contains an integer N denoting the size of an array.

The second line contains N-space separated integers denoting the array.

Output: Print all the numbers separated by space which satisfies the condition. 

Constraints: 1<=N<=10^3.

1<=Array Elements<=10^5.

Sample Input: 6

2 3 5 4 7 8

Sample Output: 

4 8

n = int(input())
a = tuple(map(int, input().split()))
for i in range(1, n, 2):
  if a[i] % 2 == 0:
    print(a[i], end=' ')

How do you rate this article?

2


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?