MCPcopy Create free account
hub / github.com/geekcomputers/Python / draw_diamond

Function draw_diamond

diamond.py:1–13  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

1def draw_diamond(n):
2 if n % 2 != 0:
3 k = 1
4 while k <= n:
5 print(" " * int((n - k) / 2) + "*" * k + " " * int((n - k) / 2))
6 k += 2
7
8 j = 1
9 while (n - 2 * j) >= 1:
10 print(" " * j + "*" * (n - 2 * j) + " " * (j))
11 j += 1
12 else:
13 print("Not an odd number. Can't draw a diamond :(")
14
15
16n = int(input("Enter an odd number: "))

Callers 1

diamond.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected