|
| 1 | +# Pattern 1 |
| 2 | +# * |
| 3 | +# ** |
| 4 | +# *** |
| 5 | +# **** |
| 6 | +# ***** |
| 7 | + |
| 8 | +# Loop through the rows from 0 to 5 (6 rows in total) |
| 9 | +for i in range(6): |
| 10 | + # Loop through the columns from 0 to i (inclusive) for each row |
| 11 | + for k in range(i+1): |
| 12 | + # Print a star with no newline character |
| 13 | + print("*", end="") |
| 14 | + # Move to the next line |
| 15 | + print() |
| 16 | + |
| 17 | +# Pattern 2 |
| 18 | +# ***** |
| 19 | +# **** |
| 20 | +# *** |
| 21 | +# ** |
| 22 | +# * |
| 23 | + |
| 24 | +# Loop through the rows from 5 to 1 (inclusive) |
| 25 | +for i in range(5, 0, -1): |
| 26 | + # Loop through the columns from 0 to i (inclusive) for each row |
| 27 | + for k in range(i): |
| 28 | + # Print a star with no newline character |
| 29 | + print("*", end="") |
| 30 | + # Move to the next line |
| 31 | + print() |
| 32 | + |
| 33 | +# Pattern 3 |
| 34 | +# * |
| 35 | +# ** |
| 36 | +# *** |
| 37 | +# **** |
| 38 | +# ***** |
| 39 | + |
| 40 | +# Loop through the rows from 0 to 4 (5 rows in total) |
| 41 | +for i in range(5): |
| 42 | + # Loop through the columns from 1 to 5 for each row |
| 43 | + for j in range(1, 6): |
| 44 | + # Print a space with no newline character if j is less than or equal to 5-i |
| 45 | + if j <= 5-i: |
| 46 | + print(" ", end="") |
| 47 | + else: |
| 48 | + # Otherwise, print a star with no newline character |
| 49 | + print("*", end="") |
| 50 | + # Move to the next line |
| 51 | + print() |
| 52 | + |
| 53 | +# Pattern 4 |
| 54 | +# ***** |
| 55 | +# **** |
| 56 | +# *** |
| 57 | +# ** |
| 58 | +# * |
| 59 | + |
| 60 | +# Loop through the rows from 5 to 1 (inclusive) |
| 61 | +for i in range(5, 0, -1): |
| 62 | + # Loop through the columns from 1 to 5 for each row |
| 63 | + for j in range(1, 6): |
| 64 | + # Print a space with no newline character if j is less than or equal to 5-i |
| 65 | + if j <= 5-i: |
| 66 | + print(" ", end="") |
| 67 | + else: |
| 68 | + # Otherwise, print a star with no newline character |
| 69 | + print("*", end="") |
| 70 | + # Move to the next line |
| 71 | + print() |
| 72 | + |
| 73 | +# Pattern 5 |
| 74 | +# * |
| 75 | +# *** |
| 76 | +# ***** |
| 77 | +# ******* |
| 78 | +# ********* |
| 79 | +# ********* |
| 80 | +# ******* |
| 81 | +# ***** |
| 82 | +# *** |
| 83 | +# * |
| 84 | + |
| 85 | +# Loop through the rows from 0 to 8 (9 rows in total) |
| 86 | +for i in range(9): |
| 87 | + # Determine the number of spaces and stars to print for this row |
| 88 | + if i <= 4: |
| 89 | + spaces = 4 - i |
| 90 | + stars = 2*i + 1 |
| 91 | + else: |
| 92 | + spaces = i - 4 |
| 93 | + stars = 17 - 2*i |
| 94 | + # Loop through the columns for each row |
| 95 | + for j in range(1, 11): |
| 96 | + # Print spaces or stars as appropriate for the current column |
| 97 | + if j <= spaces: |
| 98 | + print(" ", end="") |
| 99 | + elif j <= spaces + stars: |
| 100 | + print("*", end="") |
| 101 | + # Move to the next line |
| 102 | + print() |
0 commit comments