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
Explain the difference between social engineering and reverse social engineering.
san4es73 [151]
Social Engineering is the art of eliciting sensitive information from people by tricking them. Like through phishing, fake emails that contain a virus and fake programs. They get your password or any other sensitive information by making you think the website/program is legit. That's why you should always make sure the new website/program you visited is safe.

Reverse Social Engineering is, on the other hand, where the initial attacker becomes attacked. Or the victim redirects the attacker to someone who can counter the attacker. E.g attackers call the front desk and ask for information X. Instead or giving him information X, front desk redirects the call to the security department. An example is where the attacker is fed false information. Law enforcement agencies often perform this attack.
5 0
3 years ago
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
Write an algorithm to sum to values
Elis [28]

Answer:

There is no need to make an algorithm for this simple problem. Just add the two numbers by storing in two different variables as follows:

Let a,b be two numbers.

c=a+b;

print(c);

But, if you want to find the sum of more numbers, you can use any loop like for, while or do-while as follows:

Let a be the variable where the input numbers are stored.

while(f==1)

{

printf(“Enter number”);

scanf(“Take number into the variable a”);

sum=sum+a;

printf(“Do you want to enter more numbers? 1 for yes, 0 for no”);

scanf(“Take the input into the variable f”);

}

print(Sum)

Explanation:

hi there answer is given mar me as brainliest

5 0
3 years ago
Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number
sineoko [7]

Answer:

// using c++ language

#include "stdafx.h";

#include <iostream>

#include<cmath>

using namespace std;

//start

int main()

{

 //Declaration of variables in the program

 double start_organisms;

 double daily_increase;

 int days;

 double updated_organisms;

 //The user enters the number of organisms as desired

 cout << "Enter the starting number of organisms: ";

 cin >> start_organisms;

 //Validating input data

 while (start_organisms < 2)

 {

     cout << "The starting number of organisms must be at least 2.\n";

     cout << "Enter the starting number of organisms: ";

     cin >> start_organisms;

 }

 //The user enters daily input, here's where we apply the 5.2% given in question

 cout << "Enter the daily population increase: ";

 cin>> daily_increase;

 //Validating the increase

 while (daily_increase < 0)

 {

     cout << "The average daily population increase must be a positive value.\n ";

     cout << "Enter the daily population increase: ";

     cin >> daily_increase;

 }

 //The user enters number of days

 cout << "Enter the number of days: ";

 cin >> days;

 //Validating the number of days

 while (days<1)

 {

     cout << "The number of days must be at least 1.\n";

     cout << "Enter the number of days: ";

     cin >> days;

 }

 

 //Final calculation and display of results based on formulas

 for (int i = 0; i < days; i++)

 {

     updated_organisms = start_organisms + (daily_increase*start_organisms);

     cout << "On day " << i + 1 << " the population size was " << round(updated_organisms)<<"."<<"\n";

     

     start_organisms = updated_organisms;

 }

 system("pause");

  return 0;

//end

}

Explanation:

6 0
3 years ago
What web 2.0 features allows users to subscribe to a data plan that charges for the amount of time spent on the internet?
galina1969 [7]

Answer:

The answer to this question is given in the explanation section. The correct option is long tail

Explanation:

a.Folksonomy

Folksonomy is a way of organizing data and digital content. With Web 2.0, users can collaboratively manage and tag photos, journals and other media. As more users do this, creates a system of classification for the media and information.  so this option is not correct

b. long tail (correct option)

Some sites are able to offer services as well in which users can subscribe monthly or pay a fee every so often. An example of this would be Netflix.

c.user participation

All users have the free will to contribute to the site which makes many Web 2.0 pages public. With sites such as Wikipedia, anyone is open to the editing of articles. Information is provided two-way instead of solely from the site owner.

d.application

Web 2.0 applications that allow anyone to create and share online information or material they have created. As you know that there are number of different types of web 2.0 applications including wikis, blogs, social networking, folksonomies, podcasting & content hosting services.

3 0
3 years ago
Other questions:
  • The operating system of a computer is an example of ________ software. science-forum
    7·1 answer
  • Which of the following STEM discoverers developed a new type of computer hardware?
    11·1 answer
  • If two hosts are connected by five networks, how many frames will there be when one host sends a packet to the other host? 1 2 5
    13·1 answer
  • Which type of fiber-optic connector, containing one fiber-optic strand per connector, is connected by pushing the connector into
    7·1 answer
  • Which finger presses the Shift key on the keyboard?
    6·2 answers
  • 12. In cell A14, use the INDEX function and structured references to display the value in the first row and first column of the
    8·1 answer
  • What will be the index of leaf node in a right-skewd binary tree with height =7,where every parent has at most one child?​
    15·1 answer
  • Which is the best choice to explain why a human resource manager is so
    5·1 answer
  • 3.<br>Give two reasons why everyone should study technology<br>​
    10·1 answer
  • You are a teaching assistant for an introductory computer concepts course at your local community college. The instructor asks y
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!