Answer to Question #223651 in Python for srikanth

Question #223651
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
Sample Output 1

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]

1
Expert's answer
2021-08-07T12:36:14-0400
N = int(input())
list = list(map(int, input().split()))

print(list[N // 2 if N % 2 == 0 else N // 2 + 1::])

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS