-
Notifications
You must be signed in to change notification settings - Fork 0
/
bite119.py
36 lines (30 loc) · 835 Bytes
/
bite119.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
def generate_xmas_tree(rows=10):
"""Generate a xmas tree of stars (*) for given rows (default 10).
Each row has row_number*2-1 stars, simple example: for rows=3 the
output would be like this (ignore docstring's indentation):
*
***
*****"""
tree = []
for row in range(1, rows+1):
tree.append('*'*(row*2-1))
new_tree = []
for i, r in enumerate(tree[::-1]):
new_tree.append(i*' '+r)
xmas = ''.join([x+'\n' for x in new_tree[::-1]])
return xmas[:-1]
print(generate_xmas_tree())
default_tree = """
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
"""
print(len(generate_xmas_tree().split('\n')))
assert len(generate_xmas_tree().split('\n')) == 10