Advertisement
TornioSubito

Somma numeri pari

Jun 18th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. def sumOfEven(lis,sum=0):
  2. #@Somma solo i numeri pari della lista fornita in input
  3. #@param lis : list (of integers)
  4. #@return int (sum of even numbers of the list)
  5. if len(lis)==0:
  6. return 0
  7. elif len(lis)==1:
  8. if lis[0]%2==0:
  9. sum=sum+lis[0]
  10. return sum
  11. else:
  12. return sum
  13. else:
  14. if lis[0]%2==0:
  15. elem=lis[0]
  16. return sumOfEven(lis[1:],sum+elem)
  17. else:
  18. return sumOfEven(lis[1:],sum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement