Advertisement
ganiyuisholaafeez

Untitled

Feb 22nd, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. """ This function returns a list of factors of a number """
  2. def print_factors(numbers):
  3.     factors=[]              # Setting an Empty List
  4.     for number in range(1, numbers+1): # The range(1, number inclusive)
  5.         if numbers % number == 0:
  6.             factors.append(number)
  7.     return factors
  8.  
  9. print(print_factors(1)) # [1]
  10. print(print_factors(2)) # [1, 2]
  11. print(print_factors(10)) # [1, 2, 5, 10]
  12. print(print_factors(64)) #[1, 2, 4, 8, 16, 32, 64]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement