Last half of List:
You are given an integer N as input. Write a program to read N inputs and print a list containing the elements in the last half of the list.
Input:
The first line of input is an integer N. The second line contains N space-separated integers.
Explanation
In the example, we are given
6 numbers 1, 2, 3, 4, 5, 6 as input.
The last half of elements of the list are 4, 5, 6. So, the output should be [4, 5, 6].
Sample Output 2
In the example, we are given
5 numbers 1, 11, 13, 21, 19 as input. The last half of elements of the list are 21, 19. So, the output should be [21, 19].
Sample Input 1
6
1 2 3 4 5 6
Sample Output 1
[4, 5, 6]
Sample Input 2
5
1 11 13 21 19
Sample Output 2
[21, 19]
N=int(input())
lst = [int(N) for N in input().split()]
out=[]
i = N//2
for x in range (N):
if x>=i and x<N:
y=lst[x]
out.append(y)
print(out)
Comments
Leave a comment