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

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

3 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




LCM and GCD

You are given two integers

x and y. Find the GCD and LCM of the numbers.GCD: Greatest Common Divisor of two integers is the largest positive integer that divides each of the integers.LCM: Least Common Multiple of two integers is the smallest positive multiple of both the integers.Input

The input contains two integers

x and y separated by space.Output

The output contains

GCD and LCM for the given pair of integers.Explanation

Given

x = 6 and y = 14.The GCD of the numbers is

2. The LCM of the numbers is 42.The output is

2 42.


what will be the output of the variable L after the following code is executed?



data stream - alphxxdida . After reverse - adidaxxhpla. so here x and a doesn't changed it position. How can I do this ?

Input - alphxxdida

Output-4
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 coefficient 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 constant term is also zero, then print 0 to represent the polynomial.
For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.

Abhinav and Anjali are playing the Tic-Tac-Toe game. Tic-Tac-Toe is a game played on a grid that's three squares by three squares. Abhinav is O, and Anjali is X. Players take turns putting their marks in empty squares. The first player to get 3 of her marks in a diagonal or horizontal, or vertical row is the winner. When all nine squares are complete, the game is over. If no player has three marks in a row, the game ends in a tie. Write a program to decide the winner in the Tic-Tac-Toe game.


b)Classify following example Fast yes or no using baysean classification algorithm Engine = Small , SC/Turbo= Yes , Weight=Light , Fuel Eco= Good


Write Python code for baysean learning to dataset as given in Q1 theory paper .Assume test
data=33% and Dataset contains integers values in dataset.
b) Classify following example Fast yes or no using baysean classification algorithm
Engine = Small , SC/Turbo= Yes , Weight=Light , Fuel Eco= G

Write a python program to check if a given 3-digit number

X is an Armstrong number or not. Note: A number is an Armstrong number if the number is equal to the sum of the Nth power of its digits.


Rearrange Numbers in String


Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part.


Input


The input will be a single line containing a string.


Output


The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.


Explanation


For example, if the given string is "I am 5 years and 11 months old", the numbers are 5, 11. Your code should print the sentence after re-ordering the numbers as "I am 11 years and 5 months old".


Sample Input

I am 5 years and 11 months old

Sample Output

I am 11 years and 5 months old

Sample Input 2:

I am 11 years 5 months, 26 weeks and 38 days old

Sample output:

I am 38 years 26 months, 11 weeks and 5 days old


LATEST TUTORIALS
APPROVED BY CLIENTS