SHARE
TWEET

Untitled

a guest Apr 24th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top