Questions: 5 831

Answers by our Experts: 5 728

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!

Search & Filtering

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())



Trapezium Order
you are given an integer N . print N rows starting from 1 in the trapexium order as shown in the output of the below examples .
Input
the input contains an integer N
OUTPUT
the output should have N lines
each of the N lines should have space -seperated integers as per the trapezium order
SAMPLE INPUT 1
4
SAMPLE OUTPUT 1
1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11
NUMBERED TRIANGLE
you are given an integer N. print N rows starting from 1 in the triangle order as shown in the explanation.
INPUT
the input contains an integer N .
OUTPUT
the output shoudl have N lines .
Each of the N lines should have space -seperated integers as per the traingle order.
EXPLANATION
given N = 5
the triangle order for the given N is
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
Given an integer N, write a program that prints the count of the total number of digits between 1 and N.

Input
The input is a positive integer.

Output
The output should be a single line containing the count of the digits up to the given number.

Explanation
Given N = 10

From 1 to 9, each number contains a single digit. From 10 onwards, the numbers contain two digits.

So the output should be 9 + 2 = 11.

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.

Input

The first line of input is an integer N. The second line contains N space-separated integers.

Explanation

Sample Output 1

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].

Sample Output 2

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.

Input:

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 15


By ordering all the elements of the matrix in increasing order, the ordered matrix should be

1 2 3
5 10 11
15 20 30

Sample 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


LATEST TUTORIALS
APPROVED BY CLIENTS