Tuesday, 30 June 2020

Print numbers pattern in Python

Print - square pattern


Code : Square Pattern

Print the following pattern for the given N number of rows.

Pattern for N = 4
4444
4444
4444
4444

Input format :
Integer N (Total no. of rows)

Output format :
Pattern in N lines

Constraints
0 <= N <= 50

Sample Input 1:
7

CODE

## Read input as specified in the question
## Print the required output in given format
n = int(input())
i = 1
while i <= n:
    j = 1
    while j <= n: 
        print(n, end = '')
        j = j+1
    print()
    i = i + 1

Sample Output 1:

7777777
7777777
7777777
7777777
7777777
7777777
7777777


Print Triangular Star Pattern


Print the following pattern for the given N number of rows.

Pattern for N = 4
*
**
***
****
Note : There are no spaces between the stars (*).

Input format :
Integer N (Total no. of rows)

Output format :
Pattern in N lines

Constraints
0 <= N <= 50

Sample Input 1:
5

CODE

## Read input as specified in the question
## Print the required output in given format
n = int(input())
i = 1
while i <= n:
    j = 1
    while j <= i: 
        print('*', end = '')
        j = j+1
    print()
    i = i + 1


Sample Output 1:
*
**
***
****
*****


Code : Triangle Number Pattern

Print the following pattern for the given N number of rows.

Pattern for N = 4
1
22
333
4444

Input format :
Integer N (Total no. of rows)

Output format :
Pattern in N lines

Constraints
0 <= N <= 50

Sample Input 1:
5

CODE:

## Read input as specified in the question
## Print the required output in given format
n = int(input())
i = 1
while i <= n:
    j = 1
    while j <= i: 
        print(i, end = '')
        j = j+1
    print()
    i = i + 1


Sample Output 1:
1
22
333
4444
55555


Code : Reverse Number Pattern

Print the following pattern for the given N number of rows.

Pattern for N = 4
1
21
321
4321

Input format :
Integer N (Total no. of rows)

Output format :
Pattern in N lines

Constraints
0 <= N <= 50

Sample Input 1:
5
CODE:

## Read input as specified in the question
## Print the required output in given format
n = int(input())
i = 1
while i <= n:
    j = i
    while j >= 1: 
        print(j, end = '')
        j = j-1
    print()
    i = i + 1

Sample Output 1:
1
21
321
4321
54321


Code : Interesting Alphabets

Print the following pattern for the given number of rows.

Pattern for N = 5
E
DE
CDE
BCDE
ABCDE

Input format :
N (Total no. of rows)

Output format :
Pattern in N lines

Constraints
0 <= N <= 26

Sample Input 1:
8

CODE:

## Read input as specified in the question.
## Print output as specified in the question.start 
n = int(input())
a = 64 
it= 0
for i in range(n,0,-1):   
    while(n>=i):
        print(chr(a+i),end="")
        i=i+1                         
    print()


Sample Output 1:
H
GH
FGH
EFGH
DEFGH
CDEFGH
BCDEFGH
ABCDEFGH


Number Pattern 1

Print the following pattern for the given N number of rows.

Pattern for N = 4
1
11
111
1111

Input format :
Integer N (Total no. of rows)

Output format :
Pattern in N lines

Sample Input :
5

CODE

## Read input as specified in the question.
## Print output as specified in the question.
n = int(input())
i = 1
while i <= n:
    j = 1
    while j <= i:
        print("1", end= '')
        j = j + 1  
    print()
    i = i + 1

Sample Output :
1
11
111
1111
11111




No comments:

Post a Comment

Print numbers pattern in Python

Print - square pattern Code : Square Pattern Print the following pattern for the given N number of rows. Pattern for N = 4 4444 4444 4444 4...