Write your code: Staircase#

Write a function that returns a staircase with n steps using the hash # and underscore _ symbols.

Rules#

  1. The number of steps are either positive or negative values.

  2. Function returns a string.

  3. The steps are adjoined with the newline character \n

  4. A positive number of step denotes the staircase’s upward direction.

  5. A negative number of step denotes the staircase’s downward direction.

Example#

Upward staircase#

staircase(3)

output: "__#\n_##\n###"

or

print(staircase(3))

output:

__#
_##
###

Downward staircase#

staircase(-5)

output: "#####\n_####\n__###\n___##\n____#"

or

print(staircase(-5))

output:

#####
_####
__###
___##
____#

Function definition#

def staircase(n):
    # write your function here
  File "/tmp/ipykernel_2486/3499838049.py", line 2
    # write your function here
                              ^
SyntaxError: unexpected EOF while parsing

Testing#

Check if your function returns the expected value using the cell below.

import unittest

class UnitTests(unittest.TestCase):

    def test_coin_type(self):
        self.assertTrue(isinstance(staircase(1), str), 'The function should return a string')

    def test_negative_even(self):
        self.assertEqual(staircase(-8), "########\n_#######\n__######\n___#####\n____####\n_____###\n______##\n_______#")

    def test_negative_odd(self):
        self.assertEqual(staircase(-5), "#####\n_####\n__###\n___##\n____#")

    def test_positive_even(self):
        self.assertEqual(staircase(4), "___#\n__##\n_###\n####")

    def test_positive_odd(self):
        self.assertEqual(staircase(7), "______#\n_____##\n____###\n___####\n__#####\n_######\n#######")

unittest.main(argv=[''], verbosity=2,exit=False)