Please write a recursive function squreOddsum(num) in Python that takes A Python list of integers and returns the sum of squares of all odd numbers in the list.if the list is empty ,the function should return 0.For example- def squareOddsum(num):
- if(len(num)==0):
- return 0
- elif num[0]%2==0:
- return squareOddsum(num[1:])
- else:
- return (num[0]*num[0])+squareOddsum(num[1:])
- a=input('請輸入列表:')
- list123=list(map(int, a.split()))
- print(squareOddsum(list123))
複製代碼 |