Describe at least three additional Python experiments. Show the Python inputs and their outputs, and explain what you learned from the results of each example.
Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.Input
first line of input will be two space-separated integers, denoting the M and N.
next M lines will contain N space-separated integers.
next line will contain an integer, denoting K.Output
output should be M*N matrix by rotating the matrix by K elements.Explanation
For example, if the given M and N are 4 and 4 respectively.matrix elements are
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
If the given K is 3. Rotate each ring of the matrix by 3 elements.
In the above matrix, the elements (1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5) is a ring, similarly, the elements (6, 7, 11, 10) will make a ring.
Therefore, by rotating each ring in clockwise direction by 3 elements will give (13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14) and (10, 6, 7, 11). output should be
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Write a program to print the anti-diagonal elements in the given matrix.Input
The first line of input will contain an integer N, denoting the number of rows and columns of the input matrix.
The next N following lines will contain N space-separated integers, denoting the elements of each row of the matrix.Output
The output should be a list containing the anti-diagonal elements.Explanation
For example, if the given N is 3, and the given matrix is
1 2 3
4 5 6
7 8 9The anti diagonal elements of the above matrix are 3, 5, 7. So the output should be the list
[3, 5, 7]
Sample Input 1
3
1 2 3
4 5 6
7 8 9
Sample Output 1
[3, 5, 7]
Sample Input 2
5
44 71 46 2 15
97 21 41 69 18
78 62 77 46 63
16 92 86 21 52
71 90 86 17 96
Sample Output 2
[15, 69, 77, 92, 71]
Given a list of integers, write a program to identify the contiguous sub-list that has the largest sum and print the sum. Any non-empty slice of the list with step size 1 can be considered as a contiguous sub-list.Input
The input will contain space-separated integers, denoting the elements of the list.Output
The output should be an integer.Explanation
For example, if the given list is [2, -4, 5, -1, 2, -3], then all the possible contiguous sub-lists will be,
[2]
[2, -4]
[2, -4, 5]
[2, -4, 5, -1]
[2, -4, 5, -1, 2]
[2, -4, 5, -1, 2, -3]
[-4]
[-4, 5]
[-4, 5, -1]
[-4, 5, -1, 2]
[-4, 5, -1, 2, -3]
[5]
[5, -1]
[5, -1, 2]
[5, -1, 2, -3]
[-1]
[-1, 2]
[-1, 2, -3]
[2]
[2, -3]
[-3]Among the above contiguous sub-lists, the contiguous sub-list [5, -1, 2] has the largest sum which is 6.
Sample Input 1
2 -4 5 -1 2 -3
Sample Output 1
6
Sample Input 2
-2 -3 4 -1 -2 1 5 -3
Sample Output 2
7
Include example Python code and output with your answers.
>>> 2++2
>>> 2--2
>>> 2+-2
>>> 2-+2
Mean, Median and Mode
Given a list of integers, write a program to print the mean, median and mode.
Mean - The average value of all the numbers.
Median - The mid point value in the sorted list.
Mode - The most common value in the list. If multiple elements with same frequency are present, print all the values with same frequency in increasing order.Input
The input will be a single line containing space-separated integers.Output
The first line of output should contain the mean, round off the value to 2 decimal places.
The second line of output should contain the median, round off the value to 2 decimal places.
The third line of output should contain the mode.
Mean should always be a float value.
Median should be a float value when there are even number of elements, otherwise should be an integer value.
Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
Sample Output 1
Mean: 4.67
Median: 4.5
Mode: 2
Sum of Prime Numbers In the Input
Given a list of integers, write a program to print the sum of all prime numbers in the list of integers.
Note: One is neither prime nor composite number.Input
The input will be a single line containing space-separated integers..Output
The output should be a single line containing the sum of all prime numbers from 1 to N.Explanation
For example, if the given list of integers are
2 4 5 6 7 3 8As 2, 3, 5 and 7 are prime numbers, your code should print the sum of these numbers. So the output should be 17.
Sample Input 1
2 4 5 6 7 3 8
Sample Output 1
17
Sample Input 2
65 87 96 31 32 86 57 69 20 42
Sample Output 2
31
Sum of Prime Numbers from M to N
Given two integers M and N, write a program to print the sum of prime numbers from M to N. (Both M and N are inclusive).Input
The first line of input will contain a positive integer (M).
The second line of input will contain a positive integer (N).Output
The output should be a single line containing the sum of prime numbers from M to N.Explanation
For example, if the given M and N are 5 and 11, as all the prime numbers from 5 to 11 are 5, 7, and 11. So the output should be sum of these primes (5+7+11), which is 23.
Similarly, if the given numbers are M is 18 and N is 40, as all the prime numbers from 18 to 40 are 19, 23, 29, 31,and 37. So the output should be sum of these primes (19+23+29+31+37), which is 139.
Sample Input 1
5
11
Sample Output 1
23
Sample Input 2
18
40
Sample Output 2
139
Index of Last Occurrence
Write a program to print the index of the last occurrence of the given number N in the list.Input
The first line of input will contain space-separated integers.
The second line of input will contain an integer N.Output
The output should be the index of the last occurrence of the number N.Explanation
For example, if the given list of numbers and N are
2 4 5 6 7 8 2 4 5 2 3 8
2Number 2 present at index locations 0, 6, 9, as the last occurrence, is at index 9. So the output should be 9.
Sample Input 1
2 4 5 6 7 8 2 4 5 2 3 8
2
Sample Output 1
9
Sample Input 2
65 87 96 31 32 86 57 69 20 42 32 32
32
Sample Output 2
11
Sum of Prime Numbers In the Input
Given a list of integers, write a program to print the sum of all prime numbers in the list of integers.
Note: One is neither prime nor composite number.Input
The input will be a single line containing space-separated integers..Output
The output should be a single line containing the sum of all prime numbers from 1 to N.Explanation
For example, if the given list of integers are
2 4 5 6 7 3 8As 2, 3, 5 and 7 are prime numbers, your code should print the sum of these numbers. So the output should be 17.
Sample Input 1
2 4 5 6 7 3 8
Sample Output 1
17
Sample Input 2
65 87 96 31 32 86 57 69 20 42
Sample Output 2
31