Answer to Question #224695 in Python for kaavya

Question #224695

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-11T14:12:50-0400
n = int(input())
line = input()

list = line.split(' ')
count = int(n/-2)

print(list[count:])

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