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.
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
n = int(input())
t = int(input())
numbers = [int(input()) for _ in range(n)]
for _ in range(t):
print(numbers[int(input())])
Comments
Leave a comment