-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathdiamonds.py
57 lines (48 loc) · 2.05 KB
/
diamonds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
r"""Diamonds, by Al Sweigart [email protected]
Draws diamonds of various sizes.
View this code at https://nostarch.com/big-book-small-python-projects
/\ /\
/ \ //\\
/\ /\ / \ ///\\\
/ \ //\\ / \ ////\\\\
/\ /\ / \ ///\\\ \ / \\\\////
/ \ //\\ \ / \\\/// \ / \\\///
\ / \\// \ / \\// \ / \\//
\/ \/ \/ \/ \/ \/
Tags: tiny, beginner, artistic"""
__version__ = 0
def main():
print('Diamonds, by Al Sweigart [email protected]')
# Display diamonds of sizes 0 through 6:
for diamondSize in range(0, 6):
displayOutlineDiamond(diamondSize)
print() # Print a newline.
displayFilledDiamond(diamondSize)
print() # Print a newline.
def displayOutlineDiamond(size):
# Display the top half of the diamond:
for i in range(size):
print(' ' * (size - i - 1), end='') # Left side space.
print('/', end='') # Left side of diamond.
print(' ' * (i * 2), end='') # Interior of diamond.
print('\\') # Right side of diamond.
# Display the bottom half of the diamond:
for i in range(size):
print(' ' * i, end='') # Left side space.
print('\\', end='') # Left side of diamond.
print(' ' * ((size - i - 1) * 2), end='') # Interior of diamond.
print('/') # Right side of diamond.
def displayFilledDiamond(size):
# Display the top half of the diamond:
for i in range(size):
print(' ' * (size - i - 1), end='') # Left side space.
print('/' * (i + 1), end='') # Left half of diamond.
print('\\' * (i + 1)) # Right half of diamond.
# Display the bottom half of the diamond:
for i in range(size):
print(' ' * i, end='') # Left side space.
print('\\' * (size - i), end='') # Left side of diamond.
print('/' * (size - i)) # Right side of diamond.
# If this program was run (instead of imported), run the game:
if __name__ == '__main__':
main()