1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
levacccp [35]
3 years ago
5

In Python,The sum of the elements in a tuple can be recusively calculated as follows:The sum of the elements in a tuple of size

0 is 0Otherwise, the sum is the value of the first element added to the sum of the rest of the elementsWrite a function named sum that accepts a tuple as an argument and returns the sum of the elements in the tuple.
Computers and Technology
1 answer:
andrezito [222]3 years ago
3 0

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))

<u>Output:</u>

The sum of tuple is: 26

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.

You might be interested in
write a function that given an integer n returns the smallest integer greater than n the sume of whose digits is twice as big th
USPshnik [31]

The code below is written in javascript which gives us the integer,

<h3>The function code is</h3>

function solution (num){


//Javascript function


var x=0,sum=0,a,b;


var d=""; //variable declaration


var digits = num.toString().split('');


var Individual = digits.map(Number);


//console.log(Individual);


for (var i=0;i<Individual.length;i++)


{//For loop


x=x+Individual[i];


}


var y=x*2;


for(var i=0;i<Individual.length;i++)


{


sum=sum+Individual[i];


d=""+d+Individual[i];


if(sum==y)


break;


if(i==Individual.length-1)


{


i=-1;


continue;


}


}


console.log("the value is "+d);


}


var number = prompt("enter the number");


//Asking user for value...


console.log("the number is");


console.log(number);


solution(num

For more information on javascript, visit

brainly.com/question/16698901?referrer=searchResults

3 0
2 years ago
What kind of block do you need to check whether a sprite is touching another sprite?
Mila [183]

A event block i know this im i have been in technology for 5 months

7 0
2 years ago
What are all the physical components called?
Alecsey [184]

Physical Components to a computer are called hardware.

3 0
3 years ago
Which of the following is usually used to connect a monitor to a computer?
viva [34]

Answer:

DVI cable

Explanation:

DVI is for video signals.

Some monitors have a usb hub built in and therefore also have a USB connection, but that is not their primary function.

5 0
3 years ago
Read 2 more answers
The term citizenship means that citizens in a country:
zimovet [89]

Answer:

Its B.

Explanation:

I think

5 0
3 years ago
Other questions:
  • If an ARQ algorithm is running over a 40-km point-to-point fiber optic link then:
    12·1 answer
  • If you wanted to search for emails containing the word advanced and prevent emails containing the word new from appearing in the
    14·1 answer
  • A mobile device has stopped receiving automatic OS updates that until recently were pushed to the device.
    7·2 answers
  • Write a Python program to do the following:
    12·1 answer
  • Some computer engineering students decided to revise the LC-3 for their senior project. In designing the LC-4, they decided to c
    13·1 answer
  • Which tool can you use in spreadsheet software to display only specific data values?
    9·1 answer
  • Self contained sequences of actions to be performed are?
    6·1 answer
  • Hydraulic systems use liquids because _____.
    14·2 answers
  • Pls tell me the answer pls i need the answer
    6·2 answers
  • Employing the use of a(n) <br> will help you manage a STEM project.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!