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