Answer to Question #224608 in Python for kaavya

Question #224608

List Indexing - 3

Given N numbers, and an index, write a program to store the numbers in a list and print the number at given index. For this problem, each input will contain T test cases. Each test case will give an index Ki as input, which should be considered to print the number.

Input:

The first line of input is an integer N. The second line of input is an integer T representing the number of test cases. The next N lines contain integers representing the numbers of the list. The next T lines contain integer Ki for each line.

Output:

You need to print a number in a new line for each of the K test cases.

Explanation:

In the given example, we are given

4 numbers 1, 2, 3, 4 as input For the first test case, K=0, the number at 0th index is 1. For the second test case, K=3, the number at 3rd index is 4. So, the output should be

1

4


Sample Input 1

4

2

1

2

3

4


3

Sample Output 1

1

4

Sample Input 2

3

1

13

21

19


Sample Output 2

13




1
Expert's answer
2021-08-09T06:30:30-0400
n = int(input())
t = int(input())
numbers = [int(input()) for _ in range(n)]
for _ in range(t):
    print(numbers[int(input())])

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