Write your code: Factors#

Write a function that returns a list of all the factors (divisors) of a given integer number.

Function definition#

def get_factors(x):

    # write the code here
    
  File "/tmp/ipykernel_2157/2059605711.py", line 4
    
    ^
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_type(self):
        self.assertEqual(type(get_factors(10)), type([10]), 'The function should return a list')
    def test_size(self):
        self.assertEqual(len(get_factors(100)), 9, 'The function should return a list with lenght=9')
    def test_result_odd(self):
        self.assertEqual(get_factors(101), [1, 101])
    def test_result_even(self):
        self.assertEqual(get_factors(200), [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 200])

unittest.main(argv=[''], verbosity=2,exit=False)
test_list (__main__.UnitTests) ... ERROR
test_list_size (__main__.UnitTests) ... ERROR
test_result1 (__main__.UnitTests) ... ERROR
test_result2 (__main__.UnitTests) ... ERROR

======================================================================
ERROR: test_list (__main__.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/ipykernel_470395/2092929949.py", line 6, in test_list
    self.assertEqual(type(get_factors(10)), type([10]), 'The function should return a list')
NameError: name 'get_factors' is not defined

======================================================================
ERROR: test_list_size (__main__.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/ipykernel_470395/2092929949.py", line 8, in test_list_size
    self.assertEqual(len(get_factors(100)), 9, 'The function should return a list with lenght=9')
NameError: name 'get_factors' is not defined

======================================================================
ERROR: test_result1 (__main__.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/ipykernel_470395/2092929949.py", line 10, in test_result1
    self.assertEqual(get_factors(100), [1, 2, 4, 5, 10, 20, 25, 50, 100])
NameError: name 'get_factors' is not defined

======================================================================
ERROR: test_result2 (__main__.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/ipykernel_470395/2092929949.py", line 12, in test_result2
    self.assertEqual(get_factors(200), [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 200])
NameError: name 'get_factors' is not defined

----------------------------------------------------------------------
Ran 4 tests in 0.001s

FAILED (errors=4)
<unittest.main.TestProgram at 0x7f0ef44516a0>