Skip to content

Latest commit

 

History

History
257 lines (187 loc) · 4.99 KB

Practice_code5.md

File metadata and controls

257 lines (187 loc) · 4.99 KB
title subtitle
List DS Practice
Practice Code 5

This Notebook Contains practice question for the note on Lists.

Try working online at:
Coding Ground - Tutorials Point
Online Compiler and Debugger


Q1: Write a program to get a number n and n numbers as input and print them as a list.

Sample 1:
I/p:
3
5
2
-20
O/p: [5, 2, -20]


Q2: Get the list of integers as input, sort them and print as output.

Sample 1:
I/P:
-1 110 -10 0 20 1 60
O/P:
[-10 -1 0 1 20 60 110]


Q3: Get a list of integers as input and print the even elements present in it. (No. of even elements > 1)

Sample 1:
I/P: 10 20 5 -2 79 23335 40
O/p: [10 20 -2 40]


Q4: Write a program to get a list of integers and print their product as output. (Use reduce method).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: 13202000


Q5: Write a program to get a list of integers and print their sum as output. (Use sum method).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: 90


Q6: Write a program to get a list of integers and print their sum as output. (use loops).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: 90


Q7: Write a program to get a list of integers and print their product as output. (Use loops).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: 13202000


Q8: Write a program to get a list of integers and print their average as output. (round off to 3 decimal places).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: 12.857


Q9: Write a program to get a list of integers and print the maximum value as output. (Use max method).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: 41


Q10: Write a program to get a list of integers and print the maximum value as output. (Use loops).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: 41


Q11: Write a program to get a list of integers and print the minimum value as output. (Use min method).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: -7


Q12: Write a program to get a list of integers and print the minimum value as output. (Use loops).

Sample 1:
I/P: 10 20 5 41 -2 -7 23
O/P: -7


Q13: Write a program to get a number n and print first n terms of Fibonacci series.


Q14: Write a program to get a list of string values as input and print the values at even position as output.

Sample 1:
I/P: Hi First Second python STRING
O/P: First python


Q15: Write a program to get a list of numbers as input and print their median as output.
(Median is the center-most value of the sorted list)

Sample 1:
I/P: 2 9 1 7 4 8
O/P: 6.5


>**Sample 2:** I/P: 1 7 8 6 3 O/P: 3

Q16: Write a program to get a list of numbers as input and print their mode as output.
(Mode is the most frequent value of the given list)

Sample 1:
I/P: 2 9 1 1 4 1
O/P: 1


>**Sample 2:** I/P: 1 3 8 6 3 O/P: 3

Q17: Write a program to get the number of rows n and n rows of a matrix and print each row as a list.

Sample 1: I/P:
3
10 20 30
1 2 3
5 -4 -10
O/P:
[10, 20, 30]
[1, 2, 3]
[5, -4, -10]


Q18: Write a program to get the number of rows n and $n\times n$ matrix and print its transpose.

Sample1:
I/P:
3
10 20 30
1 2 3
5 -4 -10
O/P:
10 1 5
20 2 -4
30 3 -10


Q19: Write a program to get number of rows r and columns c and two $r \times c$ matrices and print their sum as output.
(No empty lines are provided in between the matrices)

Sample 1:
4
4
9 13 5 2
1 11 7 6
3 7 4 1
6 0 7 10
-2 4 7 31
6 9 12 6
12 11 0 1
9 10 2 3
O/P:
7 17 12 33
7 20 19 12
15 18 4 2
15 10 9 13


Q20: Write a program to get number of rows r and no. of columns c and three $r \times c$ matrices and print their sum as output.
(No empty lines are provided in between the matrices)

Sample 1:
4
4
9 13 5 2
1 11 7 6
3 7 4 1
6 0 7 10
-2 4 7 31
6 9 12 6
12 11 0 1
9 10 2 3
0 2 8 6
3 7 1 0
0 0 1 2
10 1 0 11
O/P:
7 19 20 39
10 27 20 12
15 18 5 4
25 11 9 24


Q21: Write a program to get a $m \times n$ matrix and a $p \times q$ matrix (m, n, p, q given) and print their product as output.
(No empty lines are provided in between the matrices)

Sample1:
3
2
-82 0
-57 -95
91 56
2
4
1 3 -11 24
-59 42 -15 48
O/P:
-82 -246 902 -1968
5548 -4161 2052 -5928
-3213 2625 -1841 4872


Q22: Write a program to get a list of words and sort them in lexicographic order.


Check Solution