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
What do virtually all "phishing" emails have in common?
Arisa [49]
The name of your email/or dont have any name, asking for money, spelling mistakes, and sometimes a UNSUBSCRIBE button at the bottom of the email.
6 0
3 years ago
Suppose you define a java class as follows: public class test { } in order to compile this program, the source code should be st
likoan [24]
Test.java

The classname and the filename need to match (case sensitive).
5 0
3 years ago
Select the correct answer.
kicyunya [14]

Answer:

D

Explanation:

pecialisation - departments focus on one area of work. productivity - specialism means that staff are skilled in the tasks they do. accountability - there are clear lines of management. clarity - employees understand their own and others' roles.

7 0
3 years ago
Read 2 more answers
Noise can be a barrier to communication. True or False ​
ziro4ka [17]

Answer:

True

Explanation:

This is true because noise is one of the most common communication barriers.

5 0
3 years ago
Two floating point numbers, A and B, are passed to a recursive subroutine.
Mnenie [13.5K]
The answer is (c) infinite loop
6 0
3 years ago
Other questions:
  • The ____ contains methods that allow you to set physical properties such as height and width, as well as methods that allow you
    14·1 answer
  • Which type of software-generated problems can indicate that a software bug is causing a memory error?
    11·1 answer
  • What does ‘‘negotiation’’ mean when discussing network protocols? give an example?
    15·1 answer
  • What languages other than English are spoken in the United States?
    14·1 answer
  • Multiple Choice
    6·1 answer
  • ________ is a model of computing in computer processing, storage, software, and other services which are provided as a shared po
    9·1 answer
  • Write a program that ask the user to enter air water or Steele and the distance that a sound wave will travel in the medium the
    9·1 answer
  • Which lighting direction is used to create silhouettes
    15·1 answer
  • Which format of image files can be inserted in html?​
    8·2 answers
  • Activity #2
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!