Python | Pattern Generation using time() module
This article aims to print patterns using the time() module in python.
Examples:
Input :
5
Output :
5 patterns using time with 5 rowsInput :
4
Output :
5 patterns using time with 4 rows but for diamond if you
will enter even number of rows, it will automatically do (row+1)
Code : Python program to generate patterns
# Print triangles by giving the number of stars: # For Diamond, odd number of stars will give a better result, # If the number is even then for diamond pattern, # it will automatically do (row + 1): import time n = 5 print("----------Right Angled Triangle Type 1----------") def right_angle_triangle1(n): for i in range(1, n + 1): for j in range(i): time.sleep(0.05) print("*", end ="") print() right_angle_triangle1(n) print() print("----------Right Angled Tringle Type 2----------") def right_angle_triangle2(n): for i in range(1, n + 1): for j in range(n-i): time.sleep(0.05) print(" ", end ="") for k in range(i): time.sleep(0.05) print("*", end ="") print() right_angle_triangle2(n) print() print("----------Equilateral Triangle----------") def equilateral_triangle(n): for i in range(1, n + 1): for j in range(n-i): time.sleep(0.05) print(" ", end ="") for k in range(2 * i-1): time.sleep(0.05) print("*", end ="") print() equilateral_triangle(n) print() print("----------Square----------") def square(n): for i in range(1, n + 1): for j in range(1, n + 1): time.sleep(0.05) print("*", end ="") print() square(n) print() print("----------Diamond----------") def diamond(n): cell = n//2 + 1 for i in range(1, cell + 1): for j in range(cell-i): time.sleep(0.05) print(" ", end ="") for k in range(2 * i-1): time.sleep(0.05) print("*", end ="") print() for i in range(cell-1, 0, -1): for j in range(cell-i): time.sleep(0.05) print(" ", end ="") for k in range(2 * i-1): time.sleep(0.05) print("*", end ="") print() diamond(n) |
chevron_right
filter_none
Output :
----------Right Angled Triangle Type 1----------
*
**
***
****
*****
----------Right Angled Tringle Type 2----------
*
**
***
****
*****
----------Equilateral Triangle----------
*
***
*****
*******
*********
----------Square----------
*****
*****
*****
*****
*****
----------Diamond----------
*
***
*****
***
*
Recommended Posts:
- Python | Plotting an Excel chart with pattern fills in column using XlsxWriter module
- Python – The new generation Language
- Python program to find difference between current time and given time
- pwd module in Python
- grp module in Python
- MySQL-Connector-Python module in Python
- Time Functions in Python | Set 1 (time(), ctime(), sleep()...)
- C API from Extension Module in Python | Set 1
- Platform Module in Python
- Pygorithm module in Python
- Pymatrix module in python
- OS Path module in Python
- Psutil module in Python
- Python text2digits Module
- Keyword Module in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

