Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created October 23, 2020 01:57
Show Gist options
  • Save ZechCodes/c4b81ca1dd8851009acac53c74d52de2 to your computer and use it in GitHub Desktop.
Save ZechCodes/c4b81ca1dd8851009acac53c74d52de2 to your computer and use it in GitHub Desktop.
Challenge 137 - Even or Odd Number of Factors

Challenge 137 - Even or Odd Number of Factors

Create a function that returns "even" if a number has an even number of factors and "odd" if a number has an odd number of factors.

Examples

factor_group(33) ➞ "even"

factor_group(36) ➞ "odd"

factor_group(7) ➞ "even"

Notes

  • You don't need to actually calculate the factors to solve this problem.
  • Think about why a number would have an odd number of factors.
import unittest
def factor_group(num: int) -> str:
return "" # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual("even", factor_group(33))
def test_2(self):
self.assertEqual("odd", factor_group(36))
def test_3(self):
self.assertEqual("even", factor_group(7))
def test_4(self):
self.assertEqual("odd", factor_group(1))
def test_5(self):
self.assertEqual("even", factor_group(19))
def test_6(self):
self.assertEqual("even", factor_group(27))
def test_7(self):
self.assertEqual("odd", factor_group(100))
def test_8(self):
self.assertEqual("even", factor_group(18))
def test_9(self):
self.assertEqual("odd", factor_group(16))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment