Advertisement
ganiyuisholaafeez

Odd numbers with filter()

Feb 29th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. """ User should specify the start number and end number for a range of
  2. whole numbers """
  3. lower_bound = int(input("Enter the start point: ")) # The start point
  4. upper_bound = int(input("Enter the end point (n - 1): ")) # The end point - 1
  5.  
  6. # The only_odds function declaration
  7. def only_odds(lower, upper):
  8.     print(list(filter(lambda number: number % 2 == 1, range(lower, upper))))
  9.  
  10. # The only_odds function invocation
  11. only_odds(lower_bound, upper_bound)
  12.  
  13.  
  14. # Enter the start point: 1
  15. # Enter the end point (n - 1): 9
  16. # [1, 3, 5, 7]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement