Easy_Flex

Untitled

Feb 29th, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. def only_odds(alist):   # function to determine odd numbers
  2.     odd_list = []   # empty list to contain the odd numbers
  3.     for num in alist:   # for loop to loop through all numbers in the list and determine the odd ones
  4.         if num % 2 != 0:  # condition to check if the number is odd or even
  5.             odd_list.append(num)
  6.  
  7.     return odd_list  # returns a list containing only odd numbers
  8.  
  9.  
  10. print(only_odds([1, 2, 3, 4, 5, 6, 7, 8, 9]))
Add Comment
Please, Sign In to add comment