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

Half Pyramid - 3

Given an integer 

N as a starting number and K as input, write a program to print a number pyramid of K rows as shown below.

Input

The first line of input is an integer 

N. The second line of input is an integer K.

Explanation

In the example, the given starting number is 

10, and the number of rows in the pyramid is 5.

So, the output should be

10
11 12
13 14 15
16 17 18 19
20 21 22 23 24
Sample Input 1
10
5
Sample Output 1
10 
11 12 
13 14 15 
16 17 18 19 
20 21 22 23 24
Sample Input 2
1
3
Sample Output 2
1 
2 3 
4 5 6

In the given example, the first side

A = 3, and the second side B = 4. To calculate the hypotenuse we use Pythagoras theorem. According to Pythagoras theorem, hypotenuse2 = 32 + 42

Therefore, the hypotenuse value is

5. So, the output should be 5.


W pattern with *

Write a program to print 

W pattern of N lines using an asterisk(*) character as shown below.

Note: There is a space after each asterisk * character.

Input

The first line is an integer 

N.

Explanation

For 

N = 5

The output should be

* * * * * * * * * 
 * * * * * * * * 
  * * *   * * * 
   * *     * * 
    *       *
Sample Input 1
5
Sample Output 1
* * * * * * * * * 
 * * * * * * * * 
  * * *   * * * 
   * *     * * 
    *       *
Sample Input 2
4
Sample Output 2
* * * * * * * 
 * * * * * * 
  * *   * * 
   *     *

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




Pyramid

Given an integer

N, write a program to print a pyramid of N rows as shown below.Input

The first line of input is an integer

N.Explanation

In the example, the number of rows in the pyramid is

5.So, the output should be

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
Sample Input 2
6
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 . 
0 0 0 0 0 0 0 0 0 0 0

Digit 9

You are given

N as input. Write a program to print the pattern of 2*N - 1 rows using an asterisk(*) as shown below.Note: There is a space after each asterisk * character.Input

The first line of input is an integer

N.Explanation

In the given example,

N = 4.So, the output should be

* * * *
*     *
*     *
* * * *
      *
      *
* * * *



Sample Input 1

4

Sample Output 1

* * * *
*     *
*     *
* * * *
      *
      *
* * * 

Sample Input 2

5

Sample Output 2


* * * * * 
*       *
*       *
*       *
* * * * * 
        *
        *
        *
* * * * *




Half Pyramid - 3

Given an integer

N as a starting number and K as input, write a program to print a number pyramid of K rows as shown below.Input

The first line of input is an integer

N. The second line of input is an integer K.Explanation

In the example, the given starting number is

10, and the number of rows in the pyramid is 5.So, the output should be

input-1

10

5

output-1

10

11 12

13 14 15

16 17 18 19

20 21 22 23 24


Sample Input 2

1

3

Sample Output 2

1

2 3

4 5 6




How to make object as callable video __call__
from collections import Counter
class MyCounter(Counter):
Add here required code so that we can give data to object like co1("intel")
co1 = MyCounter()
co1("intel")

For example, an array A = [10, 20, 30] and a value x = 25.

We have values 10, 20, 30 at indices 0,1,2 respectively.

  • Here index 0 is invalid because
  • 10 + 25 = 35 is less than 20 + 30 = 50
  • Here index 1 is valid because
  • 20 + 25 = 45 is greater than 10 + 30 = 40
  • Here index 2 is valid because
  • 30 + 25 = 55 is greater than 10 + 20 = 30

So there are 2 valid indices.

Sample Input 1

[1, 2, 3, 5, 7]

13

Sample Output 1

3


A number N is given as input. Write a program to check if N is positive or negative.

N = -12.5. As the value of N is less than 0, the output should be Negative.



LATEST TUTORIALS
APPROVED BY CLIENTS