Advertisement
Blessing988

Untitled

Feb 29th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. #This program declares a function that accepts a list of numbers and return a list with only odd numbers
  2.  
  3. #function
  4.  
  5. def only_odds(list_of_numbers):
  6.     odd_numbers = [  ]
  7.     for number in list_of_numbers:
  8.         if number%2==1:
  9.             odd_numbers.append(number)
  10.     print(odd_numbers)
  11.  
  12.  
  13. only_odds([1, 3, 5, 6, 7, 8])  #Example (The argument must be a list containing numbers only)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement