-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.py
More file actions
41 lines (29 loc) · 938 Bytes
/
tree.py
File metadata and controls
41 lines (29 loc) · 938 Bytes
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
# Write some code that generates a tree of any size and prints it in the console
# One level:
# *
# Two levels:
# *
# **
# Three levels:
# *
# **
# ***
# Your code here
class ChristmasTree():
def print_tree_method_one(self):
height = int(input('Type in the height of the tree: '))
for i in range(1, height + 1):
print('*' * i)
def print_tree_method_two(self):
height = int(input('Type in the height of the tree: '))
for row in range(1, height + 1):
print(' ' * (height - row) + '* ' * row)
def print_tree_method_three(self):
height = int(input('Type in the height of the tree: '))
completed_row = ''
for row in range(1, height + 1):
space = ' ' * (height - row)
for star in range(1, height + 1):
stars = '* ' * row
completed_row = space + stars
print(completed_row)