Python Answers

Questions answered by Experts: 5 288

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

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.


Given two polynomials A and B, write a program that adds the given two polynomials A and B.


The first line contains a single integer M.

Next M lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes co-efficient of Pi for polynomial A.

After that next line contains a single integer N.

Next N lines contain two integers Pj, Cj separated with space, where Pj denotes power and Cj denotes co-efficient of Pj for polynomial B.Output



if we get "0" after adding two polynomials it should print "0" as output


str_user = input('Enter your string: ')

# ord('A') = 65 ord('Z') =90

print (*[ord(i.upper())-64 for i in str_user if 65<= ord(i.upper()) <= 90],sep='-')

if we give space between two words it is printing "-"

if we give "sudheer kumar" it should print 19-21-4-8-5-5-18 11-21-13-1-18 like this.

but it is printing like this 19-21-4-8-5-5-18-11-21-13-1-18 with no space


def main():

  #Read string

  inputString = input()

  outputString=""

  for letter in inputString:

    number=getNumber(letter)

    if(number!=-1):

      outputString+=str(number)+"-"

    else:

      outputString+=letter



  print(outputString[:-1])

#This function convert letter to number

def getNumber(letter):

  alphabet = "abcdefghijklmnopqrstuvwxyz"

  for i in range(0,len(alphabet)):

    if letter.islower() and letter==alphabet[i]:

      return i+1

    if letter.isupper() and letter==alphabet[i].upper():

      return i+1

  return -1


main()

if we give python foundation we did not get the answer

what we get the answer is p-y-t-h-o-n- f-o-u-n-d-a-t-i-o-n


M, N = list(map(int,input().split()))
matrix = []
for i in range(M):
	z = [int(x) for x in input().split()]
	matrix.append(z)
K = int(input())
values = []
k =0
l =0
while (((N - k) > 0) and ((M - l) > 0)) and ((N - k)*(M-l)) > K:
	for i in range(k,N):
		values.append(matrix[k][i])
	for j in range(l+1,M):
		values.append(matrix[j][N-1])
	for i in range(N-2,k-1,-1):
		values.append(matrix[M-1][i])
	for j in range(M-2,l,-1):
		values.append(matrix[j][k])
	values = values[-K:] + values[:-K]
	c = 0
	for i in range(k,N):
		matrix[k][i] = values[c]
		c += 1
	for j in range(l+1,M):
		matrix[j][N-1] = values[c]
		c += 1
	for i in range(N-2,k-1,-1):
		matrix[M-1][i] = values[c]
		c += 1
	for j in range(M-2,l,-1):
		matrix[j][k] = values[c]
		c += 1		
	values = []
	k += 1, l += 1, M -= 1, N -= 1
for i in matrix:
  print(i)
we are getting when input is 
4 4
1 2 3 4 
5 6 7 8 
9 10 11 12 
13 14 15 16 
3
but the output is: 
9  10  11  
5  6  12  
1  7  8  
when input is:
3 4
1 2 3 4 
5 6 7 8 
9 10 11 12 
2



























Hi sir for the question:
Non-Adjacent Combinations of Two Words
Given a sentence as input, find all the unique combinations of two words and print the word combinations that are not adjacent in the original sentence in lexicographical order.
you answered like this:
((https://www.assignmentexpert.com/homework-answers/programming-and-computer-science/python/question-177142))
here in the solution we are inserting "be be" at index 0, but if we give other input, then also "be be" will be the first line of output right sir?
So can you please verify and answer it again?

The volume of a sphere is 4/3 pi r cube. write a function called print_volume(r) that takes an argument for the radius of the sphere and print the volume of the sphere. Call your print_volume function three times with different values for radius


Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.


Input

The first line contains a single integer N.

Next N lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes coefficient of Pi.


Output

Print the polynomial in the format Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is coefficient, and C0 is constant. There will be space before and after the plus or minus sign.

If the coeff is zero, then don't print the term.

If the term with the highest degree is negative, the term should represent -Cix^Pi.

For the term where power is 1, represent it as C1x instead of C1x^1.

If the polynomial degree is zero and the const term is also zero, then print 0 to represent the polynomial.

For term Cix^Pi, if the coeff of the term Ci is 1, print x^Pi instead of 1x^Pi.


Constraints

N <= 100 0 <= Pi < 1000 -1000 <= Ci <= 1000


Sample Input

5

0 2

1 3

2 1

4 7

3 6

Output:


7x^4 + 6x^3 + x^2 + 3x + 2

Given a list of numbers, write a program to print the smallest positive integer missing in the given numbers.Input


The input will be a single line containing numbers separated by space.Output


The output should be a single line containing the smallest missing number from given numbers.Explanation


For example, if the input numbers are 3, 1, 2, 5, 3, 7, 7.

The number 1, 2, 3 are present. But the number 4 is not. So 4 is the smallest positive integers that is missing from the given numbers.




Given date-time D, write a program to print the time left for the next New Year.Input


The input will be a single line containing the date-time in the string format similar to "Dec 30 2020 02:43 PM".Output


The output should be a single line containing hours and minutes left for the next new year in the format similar to "33 hours 17 minutes".Explanation


For example, if the given date-time is "Dec 30 2020 02:43 PM", the difference between "Dec 30 2020 02:43 PM" and "Jan 1 2021 00:00 AM" is 1 day 9 hours 17 minutes. The difference in hours and minutes is 1 * 24 + 9 hours and 17 minutes. So the output should be "33 hours 17 minutes".




LATEST TUTORIALS
APPROVED BY CLIENTS