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

Product of the String

You are given an alphanumeric string S.Write a program to multiply all the charcters(except trailing zeroes) in S and print the output.


Rules for multiplication:

  • If the character is digit, multiply its value.
  • If the character is an alphabetic character, multiply the product of digits of its ASCII value.


Input

The first line contains a string S.


Output

The output should be a integer denoting the product of characters.


Explanation

For N = 123a4


ASCII value of a is 97.

Product of digits of ASCII value of a is 9 *7 = 63.

Therefore the product of characters is 1*2*3*4*63*4 = 1512.


Sample Input1

123a4

Sample Output1

1512



Armstrong numbers between two intervals



Write a program to print all the Armstrong numbers in the given range



A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digits.



Input



The first line has an integer



A. The second line has an integer B.



Output



Print all Armstrong numbers separated by a space.


If there are no Armstrong numbers in the given range, print



-1.



Explanation



For



A = 150 and B = 200



For example, if we take number 153, the sum of the cube of digits



1, 5, 3 is



13 + 53 + 33 = 153.



So, the output should be



153.



Sample Input 1


150


200


Sample Output 1


153


Sample Input 2


1


3


Sample Output 2


1 2 3


Sample output 3


200


Sample input 3


-1

Pyramids Frequency

These are N pyramids in a line.You are given their heights as space-separated integers.Write a program to print the heights of the pyramids in increasing order along with their frequency.


Input

The first line of input contains space-separated integers.


Output

Each line of output should contain the height of the pyramid and its frequency in the ascending order of the pyramid's height.


Explanation

In the example, The given pyramid heights are 1,5,1,2,5,6.

The frequency of each unique pyramid height is

1 2

2 1

5 2

6 1


Sample Input1

1 5 1 2 5 6

Sample Output1

1 2

2 1

5 2

6 1


Stale Ingredients

Yasoda went to a store to buy Ingredients to make a boul of soup.While billing the order,salesperson found that some ingredients are stale.So, he wants to separate the stale ingredients from the rest.You are given the prices of the ingredients,where a negative price value indicates a stale ingredient.Write a program to help the sales person to move the prices of all the stale ingredients to left without changing the relative order of the ingredients.


Input

The first line of input contains space-separated integers.


Explanation

In the example, there are 6 ingredients with prices 11,-12,13,-14,15,16 respectively.

The prices of the stale ingredients in the given list are -12 and -14 in the order of occurence.

So, the output is -12 -14 11 13 15 16.


Sample Input1

11 -12 13 -14 15 16

Sample Output1

-12 -14 11 13 15 16


Sample Input2

21 11 -3 -2 9

Sample Output2

-3 -2 21 11 9


Write a python program to design a class representing complex numbers and having the functionality of performing addition & multiplication of two complex numbers using operator overloading

Highest Sum of Scores

The students in the class were divided into groups of three.Each student was given a T-shirt for a game.Later they were asked to calculate the score of their group by adding the jersey numbers on the T-shirt of every member.Find the group with the highest scores and print the jersey numbers on the T-shirts of every group member.


Input

The first line of the input contains an integer N that denotes the number of groups.

The next N lines of input contains the scores of students in the group separated by comma.


Output

The output contains the scores of the students of the group with maximum sum separated by space.


Explanation

Given the input lists are [[0,1,2],[3,1,0]].

The sum of the scores is highest in the group[3,1,0] i.e., 4.So the output should be 3 1 0.


Sample Input1

2

0,1,2

3,1,0

Sample Output1

3 1 0


Difficult Addition


Arjun is trying to add two numbers. Since he has learned addition recently, an addition which requires a carry is difficult for him. Your task is to print Easy if the addition does not involve a carry, Otherwise print Hard.


Input

The first line of input contains two space separated integers A and B.


Output

If the addition does not involve a carry,print Easy, otherwise print Hard.


Explanation

When calculating 229 + 390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.


Sample Input1

229 390

Sample Output1

Hard


Sample Input2

123456789 9876543218

Sample Output2

Easy


You are given space separated integers as input.



Write the program to print the maximum number among the given numbers

Algorithm,flow chart and pseudocode for sequence of comma separated numbers

Diamond



Given an integer value



N, write a program to print a number diamond of 2*N -1 rows as shown below.



Input



The first line of input is an integer



N.



Explanation



In the given example, the number of rows in the diamond is



5.



So, the output should be



. . . . 0 . . . .


. . . 0 0 0 . . .


. . 0 0 0 0 0 . .


. 0 0 0 0 0 0 0 .


0 0 0 0 0 0 0 0 0


. 0 0 0 0 0 0 0 .


. . 0 0 0 0 0 . .


. . . 0 0 0 . . .


. . . . 0 . . . .


Sample Input 1


5


Sample Output 1


. . . . 0 . . . .


. . . 0 0 0 . . .


. . 0 0 0 0 0 . .


. 0 0 0 0 0 0 0 .


0 0 0 0 0 0 0 0 0


. 0 0 0 0 0 0 0 .


. . 0 0 0 0 0 . .


. . . 0 0 0 . . .


. . . . 0 . . . .


Sample Input 2


4


Sample Output 2


. . . 0 . . .


. . 0 0 0 . .


. 0 0 0 0 0 .


0 0 0 0 0 0 0


. 0 0 0 0 0 .


. . 0 0 0 . .


. . . 0 . .

LATEST TUTORIALS
APPROVED BY CLIENTS