This notebook was prepared by Donne Martin. Source and license info is on GitHub.
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class Steps(object):
def count_ways(self, num_steps):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_steps.py
import unittest
class TestSteps(unittest.TestCase):
def test_steps(self):
steps = Steps()
self.assertRaises(TypeError, steps.count_ways, None)
self.assertRaises(TypeError, steps.count_ways, -1)
self.assertEqual(steps.count_ways(0), 1)
self.assertEqual(steps.count_ways(1), 1)
self.assertEqual(steps.count_ways(2), 2)
self.assertEqual(steps.count_ways(3), 4)
self.assertEqual(steps.count_ways(4), 7)
self.assertEqual(steps.count_ways(10), 274)
print('Success: test_steps')
def main():
test = TestSteps()
test.test_steps()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.