Python | Pattern Generation using time() module Last Updated : 01 Nov, 2023 Comments Improve Suggest changes Like Article Like Report This article aims to print patterns using the time() module in python. Examples: Input : 5 Output : 5 patterns using time with 5 rows Input : 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 Python3 # Print triangles by giving the number of stars: # For Diamond, an 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 Triangle 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) Output : ----------Right Angled Triangle Type 1----------***************----------Right Angled Triangle Type 2---------- * ** *** *********----------Equilateral Triangle---------- * *** ***** ****************----------Square----------*************************----------Diamond---------- * ******** *** * Comment More infoAdvertise with us Next Article Python | Pattern Generation using time() module S SunnyPamnani Follow Improve Article Tags : Python Articles Python Programs pattern-printing Practice Tags : pattern-printingpython Similar Reads How To Create a Countdown Timer Using Python? In this article, we will see how to create a countdown timer using Python. The code will take input from the user regarding the length of the countdown in seconds. After that, a countdown will begin on the screen of the format 'minutes: seconds'. We will use the time module here.Step-by-Step Approac 2 min read Creating Digital Clock Using Date Shower in Python Python is a versatile language used for a wide range of applications, including Graphical User Interfaces (GUI) using Tkinter. However, sometimes for simplicity, a command line can be used to create simple applications. Building a Digital Clock with a Date Shower in Python is a perfect example. This 3 min read Convert string to DateTime and vice-versa in Python A common necessity in many programming applications is dealing with dates and times. Python has strong tools and packages that simplify handling date and time conversions. This article will examine how to effectively manipulate and format date and time values in Python by converting Strings to Datet 6 min read Python program to convert seconds into hours, minutes and seconds Given an integer n (in seconds), convert it into hours, minutes and seconds. Examples:Input : 12345Output : 3:25:45Input : 3600Output : 1:00:00Let's look at different ways of doing it in Python.1. Naive ApproachThis approach uses simple mathematical calculations to get the hours, minutes, and second 3 min read Python - Time Strings to Seconds in Tuple List Given Minutes Strings, convert to total seconds in tuple list. Input : test_list = [("5:12", "9:45"), ("12:34", ), ("10:40", )] Output : [(312, 585), (754, ), (640, )] Explanation : 5 * 60 + 12 = 312 for 5:12. Input : test_list = [("5:12", "9:45")] Output : [(312, 585)] Explanation : 5 * 60 + 12 = 3 7 min read Like