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
Artemon [7]
3 years ago
9

Sum of Numbers Design a function that accepts an integer argument and returns the sum of all the integers from 1 up to the numbe

r passed as an argument. For example, if 50 is passed as an argument, the function will return the sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum. Demonstrate the function in a program.
Engineering
1 answer:
cestrela7 [59]3 years ago
4 0

Answer:

# define main to get an argument from the user, call the function, and display the final values

def main():

 # ask an argument from the user.

 number = int(input('Enter a positive integer: '))

 # solve the integral thing of the number by putting the user's argument in the addition() function

 finalSum = addition(number)

 # display the final value integral thing

 print("The integral of this number is ", finalSum, ".")

# define an addition function to find the integral

def addition(num):

 # make an if-statement to test filter things out of your calculations. In this case, 1.

 if num == 1:

   #if 1, return 1. because 1 + (1 - 1) = 1

   return 1

 # this is where the recursion actually is. This is the part that calculates

 else:

   return num + addition(num-1)

# call your main function

main()

Explanation:

This is written in Python. A link to the output can be found below.

https://Sum-of-Numbers.hufflepuffler07.repl.run

You might be interested in
. A 10W light bulb connected to a series of batteries may produce a brighter lightthan a 250W light bulb connected to the same b
Dvinal [7]

Answer:

Explanation:

From the equation:

Power dissipated= square of voltage supplied by battery ÷ Resistance of the load

i.e P= V^2/R

It means that at constant voltage, the the power consumed is inversely related to the resistance. Therefore the 10W bulb which has a higher resistance will consume less power using the sufficiently excess power dissipated to glow brighter than the 250W bulb which has a low resistance. The power dissipated will partly be used to overcome this low resistance making less power available for heating up the 250W bulb .

3 0
3 years ago
Read 2 more answers
Ventajas motor avion
Sauron [17]

Answer:

Explanation:

Usar motores eléctricos en aviones ofrece numerosas ventajas reales. A diferencia de los motores de combustión interna los motores eléctricos no necesitan aire para funcionar, lo que significa que pueden mantener toda su capacidad y potencia incluso a altitudes elevadas donde el aire es más tenue.

4 0
3 years ago
I want to solve the question
DedPeter [7]

Answer:

yes.

Explanation:

5 0
3 years ago
C#: Arrays - Ask the user how many students names they want to store. You will create two parallel arrays (e.g. 2 arrays with th
zhenek [66]

Answer:

  1. using System;      
  2. public class Program
  3. {
  4. public static void Main()
  5. {
  6.  Console.WriteLine("Enter number of students: ");
  7.  int num = Convert.ToInt32(Console.ReadLine());
  8.  string [] firstName = new string[num];
  9.  string [] lastName = new string[num];
  10.  
  11.  for(int i=0 ; i < num; i++){
  12.   Console.WriteLine("Enter first name: ");
  13.   firstName[i] = Console.ReadLine();
  14.    
  15.   Console.WriteLine("Enter last name: ");
  16.   lastName[i] = Console.ReadLine();
  17.  }
  18.  
  19.  for(int j=0; j < num; j++){
  20.   Console.WriteLine(lastName[j] + "," + firstName[j]);
  21.  }
  22. }
  23. }

Explanation:

Firstly, prompt user to enter number of student to be stored (Line 6- 7). Next, create two array, firstName and lastName with num size (Line 8-9).

Create a for-loop to repeat for num times and prompt user to enter first name and last name and then store them in the firstName and lastName array, respectively (Line 11 - 17).

Create another for loop to traverse through the lastName and firstName array and display the last name and first name by following the format given in the question (Line 19 - 21).

4 0
3 years ago
What components are included in a basic engine block?
atroni [7]
Houses the CYLINDERS, Water Jacket & Crankcase
8 0
3 years ago
Other questions:
  • The lab technician you recently hired tells you the following: Boss, an undisturbed sample of saturated clayey soil was brought
    6·1 answer
  • A 15 cm × 15 cm circuit board dissipating 20 W of power uniformly is cooled by air, which approached the circuit board at 20C w
    11·1 answer
  • Water is the working fluid in a Rankine cycle. Superheated vapor enters the turbine at 8 MPa, 560°C and the turbine exit pressur
    13·1 answer
  • What are the weight restrictions for a small UAS, including everything onboard at the time
    12·1 answer
  • 6
    5·1 answer
  • Opposition to current flow, restricts or resists current flow
    15·1 answer
  • Problem 4.041 SI Refrigerant 134a enters an insulated compressor operating at steady state as saturated vapor at -26oC with a vo
    8·1 answer
  • How many steps are there in the problem-solving process?
    9·2 answers
  • When you accelerate, the size of the front tire patch becomes____
    15·1 answer
  • 3. (5%) you would like to physically separate different materials in a scrap recycling plant. describe at least one method that
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!