OsahonE

Wk5_2

Apr 1st, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. def only_odds(nums_list):
  2.     odd_nums = []
  3.    
  4.     #iterating through the list and stating the condition that num divided by 2 must not leave a remainder equal to zero, for it to append to the odd_nums list, we have:
  5.    
  6.     for num in nums_list:
  7.         if num % 2 != 0:
  8.             odd_nums.append(num)
  9.     return odd_nums
  10.    
  11. print(only_odds([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
Advertisement
Add Comment
Please, Sign In to add comment