-
Notifications
You must be signed in to change notification settings - Fork 0
/
staircase.py
48 lines (36 loc) · 1010 Bytes
/
staircase.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
#!/bin/python3
"""
Solution to this problem:
https://www.hackerrank.com/challenges/staircase/problem
"""
import math
import os
import random
import re
import sys
import unittest
def build_staircase(n):
for hashes_count in range(1, n + 1):
spaces_count = n - hashes_count
staircase_level = ' ' * spaces_count + '#' * hashes_count
yield staircase_level
def staircase(n):
for staircase_level in build_staircase(n):
print(staircase_level)
class TestStarcase(unittest.TestCase):
def test_staircase_n_1(self):
n = 1
result = build_staircase(n)
expected = '#'
self.assertEqual(next(result), expected)
def test_staircase_n_2(self):
n = 2
result = build_staircase(n)
expected = ' #'
self.assertEqual(next(result), expected)
expected = '##'
self.assertEqual(next(result), expected)
#unittest.main()
if __name__ == '__main__':
n = int(input().strip())
staircase(n)