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

Diamond Crystal

Given an integer value N, write a program to print a diamond pattern of 2*N 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

2*5 = 10.So, the output should be


/\

/ \

/ \

/ \

/ \

\ /

\ /

\ /

\ /

\/


Sample Input 1

5

Sample Output 1

/\

/ \

/ \

/ \

/ \

\ /

\ /

\ /

\ /

\/

Sample Input 2

3

Sample Output 2

/\

/ \

/ \

\ /

\ /

\/





The game is played as follows:

The game consists of 3 turns, and the aim of the game is to score as many points as possible,Each turn begins with a roll of 6 standard dice,Matching dice (2 or more of the same number) can be set aside for points, and the remaining dice can then be re-rolled in an attempt to score more points 5s Points are “amount of dice * number on dice”, e.g. rolling three 5s is worth 15 points,The player chooses whether to set matching dice aside and whether to re-roll remaining dice, If the player chooses not to re-roll the dice, the points accumulated in the turn are added to their score and the turn ends, If no dice can be put aside after a roll, the player loses the points the potential points and the turn ends – hence, the player must decide how far to push their luck with additional rolls,The game involves quite a lot of luck, but there is also a small amount of strategy in choosing whether to set matching dice aside and whether to re-roll the remaining dice.



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.

Two Words Combination

Given a sentence as input, print all the unique combinations of two words in lexicographical order.Input


The input will be a single line containing a sentence.Output


The output should be multiple lines, each line containing the unique combination of two words in lexicographical order.Explanation


For example, if the given sentence is "raju plays cricket", the possible unique combination of two are (cricket, plays), (cricket, raju), (plays, raju). So the output should be

cricket plays
cricket raju
plays raju

Sample Input 1

raju plays cricket

Sample Output 1

cricket plays

cricket raju

plays raju

Sample Input 2

python is a programming language

Sample Output 2

a is

a language

a programming

a python

is language

is programming

is python

language programming

language python

programming python




Max Contiguous Subarray

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


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


The output should be space-separated integers.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]
[2, -4, 5, -1, 2, -3]
[-4]
[-4, 5]
[-4, 5, -1]
[-4, 5, -1, 2]
[-4, 5, -1, 2, -3]
[5]
[5, -1]
[5, -1, 2]
[5, -1, 2, -3]
[-1]
[-1, 2]
[-1, 2, -3]
[2]
[2, -3]
[-3]


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

Sample Input 1

2 -4 5 -1 2 -3

Sample Output 1

5 -1 2

Sample Input 2

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

Sample Output 2

4 -1 -2 1 5





Last half of List


This Program name is Last half of List. Write a Python program to Last half of List, it has two test cases


The below link contains Last half of List question, explanation and test cases


https://docs.google.com/document/d/12r-Wk4K7GMmpiGxHWymMhcXkUMBy8Okg/edit?usp=sharing&ouid=104486799211107564921&rtpof=true&sd=true


We need exact output when the code was run

First and Last Elements of List


This Program name is First and Last Elements of List. Write a Python program to First and Last Elements of List, it has two test cases


The below link contains First and Last Elements of List question, explanation and test cases


https://docs.google.com/document/d/1LSR6d1QTXfpHGouv_GmIKkL595o6R_IK/edit?usp=sharing&ouid=104486799211107564921&rtpof=true&sd=true


We need exact output when the code was run

List Indexing - 3


This Program name is List Indexing - 3. Write a Python program to List Indexing - 3, it has two test cases


The below link contains List Indexing - 3 question, explanation and test cases


https://docs.google.com/document/d/1F2ws8-9vz96_0wpYR82MqW1wejDjS2gf/edit?usp=sharing&ouid=104486799211107564921&rtpof=true&sd=true


We need exact output when the code was run

Create and Print List -3


This Program name is Create and Print List -3. Write a Python program to Create and Print List -3, it has two test cases


The below link contains Create and Print List -3 question, explanation and test cases


https://docs.google.com/document/d/1XFwFFMgfxj4_JbeCW_qXmh3-KnC2LtTp/edit?usp=sharing&ouid=104486799211107564921&rtpof=true&sd=true


We need exact output when the code was run

Trapezium Order

you are given an integer N . print N rows starting from 1 in the trapexium order as shown in the output of the below examples .

Input

the input contains an integer N

OUTPUT

the output should have N lines

each of the N lines should have space -seperated integers as per the trapezium order

CHECK THE LINK BELOW FOR EXACT OUTPUT

https://docs.google.com/document/d/1rMdPEY_1fttuydfFQLeJHmX_eMa66awj84hW2pnAdyI/edit




LATEST TUTORIALS
APPROVED BY CLIENTS