Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sumOfEven(lis,sum=0):
- #@Somma solo i numeri pari della lista fornita in input
- #@param lis : list (of integers)
- #@return int (sum of even numbers of the list)
- if len(lis)==0:
- return 0
- elif len(lis)==1:
- if lis[0]%2==0:
- sum=sum+lis[0]
- return sum
- else:
- return sum
- else:
- if lis[0]%2==0:
- elem=lis[0]
- return sumOfEven(lis[1:],sum+elem)
- else:
- return sumOfEven(lis[1:],sum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement