-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathchristmastime.py
55 lines (41 loc) · 1.88 KB
/
christmastime.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
"""
Author: Sebastián Romero Cruz
Fall 2022
NYU Tandon School of Engineering
"""
SPACE_CHR = ' '
def print_shifted_triangle(height, margin, symbol):
"""
print a `height`-line triangle, filled with `symbol` characters, shifted to the right by a `margin` number of
spaces. For example, an input of 3, 4, and '%' will yield the following triangle output:
%
%%%
%%%%%
:param height: An int value representing the number of "levels" in triangle
:param margin: An int value representing distance from the screen's left margin
:param symbol: A str value representing the character that will be use to draw triangle
:return: None
"""
for level_number in range(height, -1, -1):
number_of_spaces = margin + level_number
number_of_chars = 2 * (height - level_number) + 1
print(SPACE_CHR * number_of_spaces + symbol * number_of_chars)
def print_pine_tree(levels, symbol):
"""
Prints a sequence of levels-number of triangles of increasing sizes, forming a "pine tree". The triangles will be
drawn using the symbol character.
:param levels: An int value representing the number of triangles in "pine tree"
:param symbol: A str value representing the character that will be use to draw triangle
:return: None
"""
for level_number in range(1, levels + 1):
print_shifted_triangle(level_number, levels - level_number, symbol)
def main():
user_levels = int(input("Enter a positive, non-zero, integer: "))
while user_levels <= 0:
user_levels = int(input("Enter a positive, non-zero, integer: "))
user_character = input("Enter a non-whitespace, non-alphanumeric character: ")
while user_character.isalnum() or user_character.isspace():
user_character = input("Enter a non-whitespace, non-alphanumeric character: ")
print_pine_tree(user_levels, user_character)
# main()