MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / reverse_floyd

Function reverse_floyd

other/magicdiamondpattern.py:30–51  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

28
29# Function to print lower half of diamond (pyramid)
30def 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 "*"

Callers 1

pretty_printFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected