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

Exercise 1. (Sum of Integers) Implement the functions sum_iter() and sum_rec() in sum_of_ints.py that take an integer n as argum

ent and return the sum S(n) = 1 + 2 + 3 + · · · + n, computed iteratively (using a loop) and recursively. The recurrence equation for the latter implementation is
Engineering
1 answer:
MatroZZZ [7]3 years ago
8 0

Answer:

Explanation:

We'll start out by prompting users to input an integer n. Then we create 2 functions to calculate the total, one by iteration and the other by recursion.

n = input('Please input an integer n')

def sum_iter(n):

    total = 0

    for i in range(n+1):

         total += i

    return total

sum_iter(n)

def sum_rec(n):

    if n == 0:

         return 0

    else:

         return n + sum_rec(n-1)

sum_rec(n)

You might be interested in
Which of the following team members would not be involved in the design of
dimulka [17.4K]

Answer:

Writer

Explanation:

5 0
3 years ago
Water is pumped steadily through a 0.10-m diameter pipe from one closed pressurized tank to another tank. The pump adds 4.0 kW o
jekas [21]

Complete Question

Complete Question is attached below.

Answer:

V'=5m/s

Explanation:

From the question we are told that:

Diameter d=0.10m

Power P=4.0kW

Head loss \mu=10m

 \frac{P_1}{\rho g}+\frac{V_1^2}{2g}+Z_1+H_m=\frac{P_2}{\rho g}+\frac{V_2^2}{2g}+Z_2+\mu

 \frac{300*10^3}{\rho g}+35+Hm=\frac{500*10^3}{\rho g}+15+10

 H_m=(\frac{200*10^3}{1000*9.8}-10)

 H_m=10.39m

Generally the equation for Power is mathematically given by

 P=\rho gQH_m

Therefore

 Q=\frac{P}{\rho g H_m}

 Q=\frac{4*10^4}{1000*9.81*10.9}

 Q=0.03935m^3/sec

Since

 Q=AV'

Where

 A=\pi r^2\\A=3.142 (0.05)^2

 A=7.85*10^{-3}

Therefore

 V'=\frac{0.03935m^3/sec}{7.85*10^{-3}}

 V'=5m/s

5 0
3 years ago
A single fixed pulley is used to lift a load of 400N by the application of an effort of 480N in 10s through a vertical height of
Allushta [10]

Answer:

(a) the velocity ratio of the machine (V.R) = 1

(b) The mechanical advantage of the machine (M.A) = 0.833

(c) The efficiency of the machine (E) = 83.3 %

Explanation:

Given;

load lifted by the pulley, L = 400 N

effort applied in lifting the, E = 480 N

distance moved by the effort, d = 5 m

(a) the velocity ratio of the machine (V.R);

since the effort applied moved downwards through a distance of d, the load will also move upwards through an equal distance 'd'.

V.R = distance moved by effort / distance moved by the load

V.R = 5/5 = 1

(b) The mechanical advantage of the machine (M.A);

M.A = L/E

M.A = 400 / 480

M.A = 0.833

(c) The efficiency of the machine (E);

E = \frac{M.A}{V.R} \times 100\%\\\\E = 0.833 \ \times \ 100\%\\\\ E = 83.3 \ \%

4 0
3 years ago
Dean is buying a home for $170,000. The mortgage company he decided to use to finance the home requires a 10% down payment. What
ANTONII [103]
They answer is 3. $17,00
8 0
3 years ago
Read 2 more answers
java Your program class should be called RomanNumerals Write a program that asks the user to enter a number within the range of
Ann [662]

Answer:

// Scanner class is imported to allow program

// receive input

import java.util.Scanner;

// RomanNumerals class is defined

public class RomanNumerals {

   // main method that signify beginning of program execution

   public static void main(String args[]) {

       // Scanner object scan is created

       // it receive input via keyboard

       Scanner scan = new Scanner(System.in);

       // Prompt is display asking the user to enter number

       System.out.println("Enter your number: ");

       // the user input is stored at numberOfOrder

       int number = scan.nextInt();

     

           // switch statement which takes number as argument

           // the switch statement output the correct roman numeral

           // depending on user input

          switch(number){

           case 1:

               System.out.println("I");

               break;

           case 2:

               System.out.println("II");

               break;

           case 3:

               System.out.println("III");

               break;

           case 4:

               System.out.println("IV");

               break;

           case 5:

               System.out.println("V");

               break;

           case 6:

               System.out.println("VI");

               break;

           case 7:

               System.out.println("VII");

               break;

           case 8:

               System.out.println("VIII");

               break;

           case 9:

               System.out.println("IX");

               break;

           case 10:

               System.out.println("X");

               break;

           // this part is executed if user input is not between 1 to 10

           default:

               System.out.println("Error. Number must be between 1 - 10.");

     }

   }

}

Explanation:

The program is well commented. A sample image of program output is attached.

The switch statement takes the user input (number) as argument as it goes through each case block in the switch statement and match with the corresponding case to output the roman version of that number. If the number is greater 10 or less than 1; the default block is executed and it display an error message telling the user that number must be between 1 - 10.

6 0
3 years ago
Read 2 more answers
Other questions:
  • a. Draw the logic gate implementation for the Boolean function F = W X(Y + Z).b. Write the DeMorgan equivalent Boolean statement
    9·1 answer
  • Vending machine controller (adapted from Katz, "Contemporary Logic Design") Design and implement a finite state machine that con
    10·1 answer
  • Coal fire burning at 1100 k delivers heat energy to a reservoir at 500 k. Find maximum efficiency.
    6·1 answer
  • Match each titration term with its definition.
    15·1 answer
  • A triangular roadside channel is poorly lined with riprap. The channel has side slopes of 2:1 (H:V) and longitudinal slope of 2.
    9·1 answer
  • Refrigerant-134a enters an adiabatic compressor at -30oC as a saturated vapor at a rate of 0.45 m3 /min and leaves at 900 kPa an
    13·1 answer
  • Which kind of fracture (ductile or brittle) is associated with each of the two crack propagation mechanisms?
    6·1 answer
  • A steel plate has a hole drilled through it. The plate is put into a furnace and heated. What happens to the size of the inside
    9·1 answer
  • Who invented a control unit for an artificial heart?<br> ements<br> ante
    8·1 answer
  • Do plastic materials have high or low ductility? Explain why.​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!