please see the output and correct the code :--
Input:---
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output :--
1 2 3 4 5 6 7 8 9 10 11 12 16 15 14 13
Input 2:---
3 4
1 2 3 4
10 11 12 5
9 8 7 6
Output 2:--
1 2 3 4 5 12 11 10 9 8 7 6
def read_matrix():
line = input()
words =line.split()
n = int(words[0])
m = int(words[1])
mat = []
for i in range(n):
row = []
line = input()
words = line.split()
for j in range(m):
row.append(int(words[j]))
mat.append(row)
return mat
def print_zig_zag(mat):
for i in mat:
for j in i:
print(j,end=" ")
print_zig_zag(read_matrix())
Please correct these code;--
def read_matrix():
line = input()
words =line.split()
n = int(words[0])
m = int(words[1])
mat = []
for i in range(n):
row = []
line = input()
words = line.split()
for j in range(m):
row.append(int(words[j]))
mat.append(row)
return mat
def print_zig_zag(mat):
Zig-zag order in matrix;;
Input:---
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output :--
1 2 3 4 5 6 7 8 9 10 11 12 16 15 14 13
Given a string in camel case, write a python program to convert the given string from camel case to snake case.
how to slove and what is wrong in my code
w = input()
first_char = w[0]
first_char = first_char.lower()
#print(first_char)
remining_chars = w[1:]
capl = 0
for char in remining_chars:
if char == char.upper():
break
capl -= 1
lower = w[:capl].lower()
new = w[lower:]
print(new)
Last half of List:
You are given an integer N as input. Write a program to read N inputs and print a list containing the elements in the last half of the list.
The first line of input is an integer N. The second line contains N space-separated integers.
Explanation
In the example, we are given
6 numbers 1, 2, 3, 4, 5, 6 as input.
The last half of elements of the list are 4, 5, 6. So, the output should be [4, 5, 6].
In the example, we are given
5 numbers 1, 11, 13, 21, 19 as input. The last half of elements of the list are 21, 19. So, the output should be [21, 19].
Sample Input 1
6
1 2 3 4 5 6
Sample Output 1
[4, 5, 6]
Sample Input 2
5
1 11 13 21 19
Sample Output 2
[21, 19]
First and Last Elements of List
You are given an integer N as input. Write a program to read N integers and print a list containing the first and last two inputs.
The first line of input is an integer N. The next N lines each contains an integer.
Explanation:
In the given example, we are given
6 numbers 1, 2, 3, 4, 5, 6 as input.
The list should contain first two integers 1, 2 and last two integers 5, 6 So, the output should be [1, 2, 5, 6].
Sample Input 1:
6
1
2
3
4
5
6
Sample Output 1:
[1, 2, 5, 6]
Sample Input 2:
5
1
11
13
21
19
Sample Output 2:
[1, 11, 21, 19]
Ordered Matrix
Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.Output
The output should be M lines containing the ordered matrix.
Note: There is a space at the end of each line.Explanation
For example, if the given M is 3 and N is 3, read the inputs in the next three lines if the numbers given in the next three lines are the following.
1 20 3
30 10 2
5 11 15By ordering all the elements of the matrix in increasing order, the ordered matrix should be
1 2 3
5 10 11
15 20 30Sample Input 1
3 3
1 20 3
30 10 2
5 11 15
Sample Output 1
1 2 3
5 10 11
15 20 30
Sample Input 2
2 5
-50 20 3 25 -20
88 17 38 72 -10
Sample Output 2
-50 -20 -10 3 17
20 25 38 72 88
Zig-zag order in matrix;;
Input:---
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output :--
1 2 3 4 5 6 7 8 9 10 11 12 16 15 14 13
Input 2:---
3 4
1 2 3 4
10 11 12 5
9 8 7 6
Output 2:--
1 2 3 4 5 12 11 10 9 8 7 6