Skip to content

Commit 79bccf8

Browse files
author
Dan Finn
committed
much cleaner using range
1 parent 15ce2f6 commit 79bccf8

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

character_pyramid.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@
77
pyramid_character = raw_input("Enter some text: ")
88
pyramid_size = int(raw_input("And the size of your side word pyramid: "))
99

10+
1011
def create_pyramid(character, size):
1112
""" Prints a sideword pyramid """
12-
loop_counter = 1
13-
increment = 1
14-
while loop_counter > 0:
15-
if increment:
16-
print character * loop_counter
17-
loop_counter += 1
18-
if loop_counter == size:
19-
# You've reached the top, start heading down the other side
20-
print character * loop_counter
21-
increment = 0
22-
else:
23-
loop_counter -= 1
24-
print character * loop_counter
13+
for i in range(1, size + 1):
14+
print character * i
15+
for i in range(size -1 , 1, -1):
16+
print character * i
2517

2618

2719
create_pyramid(pyramid_character, pyramid_size)

0 commit comments

Comments
 (0)