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

Sum of the series

Write a program to find the sum 

S of the series where S = x - x^3 + x^5 + ....... upto N terms.

Input

The first line of input is an integer 

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

Explanation

If we take 

X value as 2 in the series upto 5 terms.

Then the series is 2 - 23 + 25 - 27 + 29

So, the output should be 

410.

Sample Input 1
2
5
Sample Output 1
410
Sample Input 2
3
2
Sample Output 2
-24

Inverted Solid Right Triangle

Given an integer number 

N as input. Write a program to print the right-angled triangular pattern of N lines 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 the solid right angled triangle of side 

4. Therefore, the output should be

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

Solid Right Angled Triangle - 2

Given an integer number 

N as input. Write a program to print the right-angled triangular pattern of N lines 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, the solid right-angled triangle of side 

5. Therefore, the output should be

        * 
      * * 
    * * * 
  * * * * 
* * * * *
Sample Input 1
4
Sample Output 1
      * 
    * * 
  * * * 
* * * *
Sample Input 2
6
Sample Output 2
          * 
        * * 
      * * * 
    * * * * 
  * * * * * 
* * * * * *

Right Angled Triangle - 3

Given an integer number 

N as input. Write a program to print the right-angled triangular pattern of N rows as shown below.

Input

The first line of input is a positive integer.

Explanation

For example, if the given number is 

5, the output should be

______
|    /
|   /
|  /
| /
|/
Sample Input 1
5
Sample Output 1
______
|    /
|   /
|  /
| /
|/
Sample Input 2
7
Sample Output 2
________
|      /
|     /
|    /
|   /
|  /
| /
|/

Hollow Right Triangle - 2

Given an integer number 

N as input. Write a program to print the hollow right-angled triangular pattern of N lines 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 the hollow right angled triangle of side 

5. Therefore, the output should be

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

Hollow Right Triangle

Given an integer number 

N as input. Write a program to print the hollow right-angled triangular pattern of N lines 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 the hollow right angled triangle of side 

4. Therefore, the output should be

* * * *
  *   *
    * *
      *
Sample Input 1
4
Sample Output 1
* * * * 
  *   *
    * *
      *
Sample Input 2
6
Sample Output 2
* * * * * * 
  *       *
    *     *
      *   *
        * *
          *


write a program to print the values as given in output

input: [1, 2, 3, 4, [8, 7, 6, 5], 9, 10, 11, 12, [16, 15, 14, 13], 17, 18, 19, 20, [22, 22, 21, 20]]

output : 1,2,3,4,8,7,6,5,9,10,11,12,16,15,14,13,17,18,19,20,22,22,21,20


Largest Number in the List:

You are given space-separated integers as input. Write a program to print the maximum number among the given numbers.


Product of Elements in the List:

You are given a space-separated list of integers as input. Write a program to print the product of these numbers.


Add two polynomials

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


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


Print the addition of polynomials A and B.

The format for printing polynomials is: Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is co-efficient and C0 is constant, there will be space before and after the plus or minus sign.




Input 2

4

0 5

1 0

2 10

3 6

4

0 -5

1 0

2 -10

3 -6


output





LATEST TUTORIALS
APPROVED BY CLIENTS