Answer to Question #223650 in Python for srikanth

Question #223650
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 testcases. Each testcase 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 testcases. 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 testcases.

Explanation

In the given example, we are given 

4 numbers 1, 2, 3, 4 as input For the first testcase, K=0, the number at 0th index is 1. For the second testcase, 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
0
3
Sample Output 1
1
4
Sample Input 2
3
1
13
21
19
0
Sample Output 2
13

1
Expert's answer
2021-08-09T02:30:38-0400
n = int(input('Enter total numbers in list here: '))
k = int(input('Enter number of testcases: '))
a = []
for i in range(n):
    j = int(input('Enter number in list here: '))
    a.append(j)
for m in range(k):
    b = int(input('Enter index here: '))
    print(a[b])

Enter total numbers in list here: 4
Enter number of testcases: 2
Enter number in list here: 1
Enter number in list here: 2
Enter number in list here: 3
Enter number in list here: 4
Enter index here: 0
1
Enter index here: 3
4

Enter total numbers in list here: 3
Enter number of testcases: 1
Enter number in list here: 13
Enter number in list here: 21
Enter number in list here: 19
Enter index here: 0
13

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