Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Patterns in Python

The document contains a series of Python programming exercises focused on generating various patterns using loops. Each question provides a specific pattern to be printed, along with the corresponding Python code to achieve that output. The patterns include numerical sequences, asterisks, and letters from the alphabet.

Uploaded by

aazilios08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Patterns in Python

The document contains a series of Python programming exercises focused on generating various patterns using loops. Each question provides a specific pattern to be printed, along with the corresponding Python code to achieve that output. The patterns include numerical sequences, asterisks, and letters from the alphabet.

Uploaded by

aazilios08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Patterns in Python (TN 12th CS)

Qn no : 1

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

for i in range(1,6):
for j in range(1,i+1):
print(j,end = " ");
print();

Qn no : 2

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

for i in range(1,6,1):
for j in range(1,7-i):
print(j,end = " ");
print();

Qn no : 3

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

for i in range(1,6):
for j in range(1,i+1):
print(i,end = " ");
print();

Qn no : 4

*
* *
* * *
* * * *
* * * * *
str = "* "
for i in range(1,6):
print(str*i);

Qn no : 5

* * * * *
* * * *
* * *
* *
*

str = "* "


for i in range(5,0,-1):
print(str*i);

Qn no : 6

A
A B
A B C
A B C D
A B C D E

str = "ABCDE";
length = len(str);
for i in str:
print(str[0:length:1]);
length-=1;

(or)

for i in range(65,70):
for j in range(65,i+1):
print(chr(j),end=" ");
print();

[ASCII : a=97 , z = 122 ; A = 65 to Z = 90

Qn no : 7

C O M P U T E R
C O M P U T E
C O M P U T
C O M P U
C O M P
C O M
C O
C

str1='COMPUTER'
index=len(str1) #8
for i in str1:
print(str1[0: index : 1])
index-=1

Qn no : 8

C
C O
C O M
C O M P
C O M P U
C O M P U T
C O M P U T E
C O M P U T E R

str = "COMPUTER";
length = 0;
for i in str:
print(str[0:(length+1):1]);
length+=1;

You might also like