Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #Write a function that accepts a list of integers as parameter and returns the
  2. #sum of all odd numbers in the list. If there are no odd numbers, it should return 0.
  3.  
  4. def calc_oddsum(list_in):
  5. oddlist = []
  6. summa = 0
  7. for item in list_in:
  8. if item % 2 != 0:
  9. oddlist.append(item)
  10. for odditem in oddlist:
  11. summa = summa + odditem
  12. if not oddlist:
  13. return 0
  14. else:
  15. return summa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement