Answer:
Following are the program in the Python Programming Language.
# Define the function
def Sum(tu):
# Check if the tuple contain 0
if len(tu)==0:
#Then, Return 0
return 0
#Otherwise
else:
#call the recursive function
return tu[0]+Sum(tu[1:])
#Set tuple type variable
tu=(2,5,1,8,10)
#print and call the function
print("The sum of tuple is:",Sum(tu))
Output:
The sum of tuple is: 26
Step-by-step explanation:
Here, we define a function "sum()" and pass an argument "tu" which stores the tuple type value, inside the function.
- Set the if conditional statement to check condition is the length of the tuple is 0 then, return 0.
- Otherwise, call and return the sum of the tuple which is recursively calculated and close the function.
Finally, set the tuple type variable "tu" and initialize the value in it then, print and call the function sum.