This section contains two methods of finding odd numbers.
odd.py
#!/usr/bin/env python3 class ODD_NUMBERS: def __init__(self, num): self.num = num def odd_numbers_perSQ(self): """DOC: Studying mathematics during my Bachelor's in Electrical Engineering degree, I found patterns that the difference between perfect squares is a prime number in a series starting at 3. 4 - 1 = 3 9 - 4 = 5 16 - 9 = 7 and so on. """ odd_list = [] first_odd = 1 odd_list.append(first_odd) count = 1 while count < self.num: next_one = ((count + 1) ** 2) - (count ** 2) odd_list.append(next_one) count += 1 print("{}".format(odd_list)) print("") def odd_numbers(self): """DOC: This method doubles the number and checks each one if it is an odd number """ odd_list2 = [] for i in range(self.num * 2): if i % 2 != 0: odd_list2.append(i) print("{}".format(odd_list2))
odd_main.py
#!/usr/bin/env python3 from odd import * def main(): print("two methods of finding the first x prime numbers" ) print("") O = ODD_NUMBERS(10) print(O.odd_numbers_perSQ.__doc__) O.odd_numbers_perSQ() print(O.odd_numbers.__doc__) O.odd_numbers() if __name__ == '__main__': main()
Output
DOC: Studying mathematics during my Bachelor's in Electrical Engineering degree, I found patterns that the difference between perfect squares is a prime number in a series starting at 3. 4 - 1 = 3 9 - 4 = 5 16 - 9 = 7 and so on. [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] DOC: This method doubles the number and checks each one if it is an odd number [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] Process finished with exit code 0