Pattern programming in Python


 To print a star pattern in Python, you can use loops and conditional statements to control the flow of the program. Here's an example of how to print a triangle pattern of stars:

for i in range(1, 6):

    for j in range(i):

        print("*", end="")

    print("")

Output:

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

Explanation:

This code uses two nested for loops. The outer loop for i in range(1, 6) runs 5 times, and the inner loop for j in range(i) runs i times. The end parameter in the print function is set to an empty string, so the stars are printed on the same line.

You can modify the code to print different patterns by changing the loop conditions, the contents of the loops, or by adding additional loops.




See Also :