Print the lower half of a diamond pattern with '*' characters. Args: n (int): Size of the pattern. Examples: >>> reverse_floyd(3) '* * * \\n * * \\n * \\n ' >>> reverse_floyd(5) '* * * * * \\n * * * * \\n * * * \\n * * \\n *
(n)
| 28 | |
| 29 | # Function to print lower half of diamond (pyramid) |
| 30 | def reverse_floyd(n): |
| 31 | """ |
| 32 | Print the lower half of a diamond pattern with '*' characters. |
| 33 | |
| 34 | Args: |
| 35 | n (int): Size of the pattern. |
| 36 | |
| 37 | Examples: |
| 38 | >>> reverse_floyd(3) |
| 39 | '* * * \\n * * \\n * \\n ' |
| 40 | |
| 41 | >>> reverse_floyd(5) |
| 42 | '* * * * * \\n * * * * \\n * * * \\n * * \\n * \\n ' |
| 43 | """ |
| 44 | result = "" |
| 45 | for i in range(n, 0, -1): |
| 46 | for _ in range(i, 0, -1): # printing stars |
| 47 | result += "* " |
| 48 | result += "\n" |
| 49 | for _ in range(n - i + 1, 0, -1): # printing spaces |
| 50 | result += " " |
| 51 | return result |
| 52 | |
| 53 | |
| 54 | # Function to print complete diamond pattern of "*" |