Add Chapter 8 python files
This commit is contained in:
parent
2424fa6028
commit
5c38f5ef86
6 changed files with 228 additions and 0 deletions
20
thinkcspy/Chapter-8-Exercises/Python-files/Problem2.py
Normal file
20
thinkcspy/Chapter-8-Exercises/Python-files/Problem2.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 8
|
||||
# Problem 2
|
||||
|
||||
def print_triangular_numbers(n):
|
||||
# your code here
|
||||
i = 1
|
||||
|
||||
while i <= n:
|
||||
trinum = 0
|
||||
bound = i
|
||||
|
||||
while bound > 0:
|
||||
trinum += bound
|
||||
bound -= 1
|
||||
|
||||
print(i, "\t", trinum)
|
||||
i += 1
|
||||
|
||||
print_triangular_numbers(5)
|
||||
Loading…
Reference in a new issue