DEV Community

Keerti Sadana S
Keerti Sadana S

Posted on

PYTHON - PATTERNS 3

Diamond Pattern:

for row in range(1,6):
    for col in range(1, 6-row):
        print(end=' ')
    for col in range(1,row+1):
        print('*',end=' ')
    print()

for row in range(1,6):
    for col in range(1, row+1):
        print(end=' ')
    for col in range(1,6-row):
        print('*',end=' ')
    print()

Enter fullscreen mode Exit fullscreen mode

Output:

    * 
   * * 
  * * * 
 * * * * 
* * * * * 
 * * * * 
  * * * 
   * * 
    * 
Enter fullscreen mode Exit fullscreen mode

Floyd Triangle:

no = 1
for row in range(1,6):
    for col in range(1,row+1):
        print(no,end=' ')
        no+=1
    print()
Enter fullscreen mode Exit fullscreen mode

Output:

1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
Enter fullscreen mode Exit fullscreen mode

Pattern:

for row in range(1,6):
    for col in range(row):
        print(col % 2, end=" ")
    print()
Enter fullscreen mode Exit fullscreen mode

Output:

0 
0 1 
0 1 0 
0 1 0 1 
0 1 0 1 0 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)