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
/\
/ \
/ \
\ /
\ /
\/
Maximum:
You are given N number of inputs. Print the maximum of them after each input.
Input
The first line of input is an integer N. The next N lines each contain an integer as input.
Explanation
In the example, you are given
6 inputs 1, 0, 3, 2, 9, 8.
1 is maximum in the input 1.
1 is maximum in the input 1, 0.
3 is maximum in the input 1, 0, 3.
3 is maximum in the input 1, 0, 3, 2.
9 is maximum in the input 1, 0, 3, 2, 9.
9 is maximum in the input 1, 0, 3, 2, 9, 8.
So, the output should be
1
3
3
9
9
Sample Input 1
6
1
3
2
9
8
Sample Output 1
1
1
3
3
9
9
Sample Input 2
5
1
2
3
4
5
Sample Output 2
1
2
3
4
5
Hyphenate Letters:
You are given a word W as input. Print W by adding a hyphen (-) between each letter in the word.
Input
The first line of input is a string W.
Explanation
In the given example, the word is Hello.
So, the output should be
H-e-l-l-o.
Sample Input 1
Hello
Sample Output 1
H-e-l-l-o
Sample Input 2
Everyone
Sample Output 2
E-v-e-r-y-o-n-e
Last half of List:
You are given an integer N as input. Write a program to read N inputs and print a list containing the elements in the last half of the list.
Input:
The first line of input is an integer N. The second line contains N space-separated integers.
Explanation
In the example, we are given
6 numbers 1, 2, 3, 4, 5, 6 as input.
The last half of elements of the list are 4, 5, 6. So, the output should be [4, 5, 6].
Sample Output 2
In the example, we are given
5 numbers 1, 11, 13, 21, 19 as input. The last half of elements of the list are 21, 19. So, the output should be [21, 19].
Sample Input 1
6
1 2 3 4 5 6
Sample Output 1
[4, 5, 6]
Sample Input 2
5
1 11 13 21 19
Sample Output 2
[21, 19]
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
SAMPLE INPUT 1
4
SAMPLE OUTPUT 1
1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11
Given an integer N, write a program which reads N inputs and prints the product of the given input integers.by using while loop
Given a string, write a program to return the sum and average of the digits of all numbers that appear in the string, ignoring all other characters.
Numbered Triangle
You are given an integer N. Print Nrows starting from 1 in
the triangle order as shown in the explanation.
Input
The input contains an integer N
Output
The output should have N lines.
Each of the N lines should have space-separated integers as per the triangle order.
INPUT 1 :
5
OUTPUT 1:
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
INPUT 2 :
4
OUTPUT 2:
1
2 5
3 6 8
4 7 9 10
Trapezium Order
You are given an integer N Print N rows starting from 1 in
the trapezium 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-separated stegers as per the trapezium order.
Sample Input 1
4
Sample Output 1
1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11
please see the output and correct the code :--
Input:---
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output :--
1 2 3 4 5 6 7 8 9 10 11 12 16 15 14 13
Input 2:---
3 4
1 2 3 4
10 11 12 5
9 8 7 6
Output 2:--
1 2 3 4 5 12 11 10 9 8 7 6
def read_matrix():
line = input()
words =line.split()
n = int(words[0])
m = int(words[1])
mat = []
for i in range(n):
row = []
line = input()
words = line.split()
for j in range(m):
row.append(int(words[j]))
mat.append(row)
return mat
def print_zig_zag(mat):
for i in mat:
for j in i:
print(j,end=" ")
print_zig_zag(read_matrix())