Skip to content

Commit b582412

Browse files
authored
Update and rename ForLoopExample.py to simple_scripts/for_loop_mountain.py
Made program more comprehensive
1 parent 26058f8 commit b582412

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

ForLoopExample.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

simple_scripts/for_loop_mountain.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# Accept User Input, consider (4)
3+
n = int(raw_input("How big? "))
4+
5+
# Building block of our mountain of money
6+
s = '$'
7+
8+
# Process for constructing mountain
9+
# Since n = 4,
10+
# range (1, n+1) would be all the integers from 1 to 4 including 1 and 4
11+
# Mountain formed would be:
12+
# $ i = 1, ' ' * n-i = 4-1 = 3 is empty space taken 3 times, s*i is '$' taken once(i times)
13+
# $$ i = 2, ' ' * n-i = 4-2 = 2 , s*i is '$' taken twice(i times)
14+
# $$$ and so on
15+
# $$$$
16+
# Again, notice how i and n change for each iteration
17+
for i in range( 1 , n+1):
18+
print (' ' *(n-i) + s*i)
19+
20+
21+
print("\n")
22+
23+
24+
# Other variant
25+
s = '$$'
26+
for i in range( 1 , n+1):
27+
print (' ' *(n-i) + s*i)

0 commit comments

Comments
 (0)