Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Write a function that accepts a list of integers as parameter and returns the
- #sum of all odd numbers in the list. If there are no odd numbers, it should return 0.
- def calc_oddsum(list_in):
- oddlist = []
- summa = 0
- for item in list_in:
- if item % 2 != 0:
- oddlist.append(item)
- for odditem in oddlist:
- summa = summa + odditem
- if not oddlist:
- return 0
- else:
- return summa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement