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

In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other
two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message
indicating whether the triangle is a right triangle.

Write a program to print the anti-diagonal elements in the given matrix.

Input

The first line of input will contain an integer N, denoting the number of rows and columns of the input matrix.

The next N following lines will contain N space-separated integers, denoting the elements of each row of the matrix.

Output

The output should be a list containing the anti-diagonal elements.

Explanation

For example, if the given N is 3, and the given matrix is

1 2 3

4 5 6

7 8 9

The anti diagonal elements of the above matrix are 3, 5, 7. So the output should be the list

[3, 5, 7]

Sample Input 1

3

1 2 3

4 5 6

7 8 9

Sample Output 1

[3, 5, 7]

Sample Input 2

5

44 71 46 2 15

97 21 41 69 18

78 62 77 46 63

16 92 86 21 52

71 90 86 17 96

Sample Output 2

[15, 69, 77, 92, 71]


Given a list of integers, write a program to identify the contiguous sub-list that has the largest sum and print the sum. Any non-empty slice of the list with step size 1 can be considered as a contiguous sub-list.

Input


The input will contain space-separated integers, denoting the elements of the list.

Output


The output should be an integer.

Explanation


For example, if the given list is [2, -4, 5, -1, 2, -3], then all the possible contiguous sub-lists will be,


[2]

[2, -4]

[2, -4, 5]

[2, -4, 5, -1]

[2, -4, 5, -1, 2]

[-4]

[-4, 5]

[-4, 5, -1]

[-4, 5, -1, 2]

[5]

[5, -1]

[5, -1, 2]

[-1]

[-1, 2]

[2]

Among the above contiguous sub-lists, the contiguous sub-list [5, -1, 2] has the largest sum which is 6.

Sample Input 1

2 -4 5 -1 2 -3

Sample Output 1

6


Sample Input 2

-2 -3 4 -1 -2 1 5 -3

Sample Output 2

7




Given a list of integers, write a program to identify the contiguous sub-list that has the largest sum and print the sum. Any non-empty slice of the list with step size 1 can be considered as a contiguous sub-list.

Input


The input will contain space-separated integers, denoting the elements of the list.

Output


The output should be an integer.

Explanation


For example, if the given list is [2, -4, 5, -1, 2, -3], then all the possible contiguous sub-lists will be,


[2]

[2, -4]

[2, -4, 5]

[2, -4, 5, -1]

[2, -4, 5, -1, 2]

[-4]

[-4, 5]

[-4, 5, -1]

[-4, 5, -1, 2]

[5]

[5, -1]

[5, -1, 2]

[-1]

[-1, 2]

[2]

Among the above contiguous sub-lists, the contiguous sub-list [5, -1, 2] has the largest sum which is 6.

Sample Input 1

2 -4 5 -1 2 -3

Sample Output 1

6


Sample Input 2

-2 -3 4 -1 -2 1 5 -3

Sample Output 2

7




Compare last three characters
Explanation given strings are apple,pimple in both the strings the last three characters ple are comman

CS Python Fundamentals Assignment 1: Silly Sentences


Give an example of a nested conditional that can be modified to become a single conditional and show the equivalent single conditional

Give a strategy for avoiding nested conditionals .


You are given a square matrix of size NxN, write a program to print the sum of upper and lower triangular elements.
Upper triangle consists of elements on the anti-diagonal and above it. The lower triangle consists of elements on the anti-diagonal and below it.

Explanation:
In the example,if the given matrix is

1 2 3
4 5 6
7 8 9

The upper triangle consists of elements on the anti-diagonal and above on it.

1 2 3
4 5
7

The sum of upper triangle elements is (1+2+3+4+5+7) equal to 22.
The lower triangle consists of elements on the anti-diagonal and below to it.

3
5 6
7 8 9

The sum of lower triangle elements is (3+5+6+7+8+9) equal to 38.

So the output should be

22
38
Write a program to print a parallelogram pattern with * characters. The size N represents the length (the number of * characters in each line)& breadth ( the number of lines) of the parallelogram.
The slope of the parallelogram T represents the number of extra spaces a line should have in the beginning compared to its next line. The last line of the pattern does not have any spaces in the beginning.

Explanation:
Given N=3 and T=2
Each line should have 3 star(*) characters.
The last line should have 0 spaces at the beginning.
Each line has 2 extra spaces characters when compared to its next line.

Input: 2 2
Output: **
**
Input: 3 2
Output: ***
***
***
LATEST TUTORIALS
APPROVED BY CLIENTS