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
Mariulka [41]
3 years ago
15

a.Write a Python function sum_1k(M) that returns the sum푠푠= ∑1푘푘푀푀푘푘=1b.Compute s for M = 3 by hand and write

another function test_sum_1k() that calls sum_1k(3) and checks that the answer is correct. When you call the sum_1k(3) function, you will see some messages according to if the test is successful or not.
Computers and Technology
1 answer:
stealth61 [152]3 years ago
8 0

Answer:

def sum_1k(M):

   s = 0

   for k in range(1, M+1):

       s = s + 1.0/k

   return s

def test_sum_1k():

   expected_value = 1.0+1.0/2+1.0/3

   computed_value = sum_1k(3)

   if expected_value == computed_value:

       print("Test is successful")

   else:

       print("Test is NOT successful")

test_sum_1k()

Explanation:

It seems the hidden part is a summation (sigma) notation that goes from 1 to M with 1/k.

- Inside the <em>sum_1k(M)</em>, iterate from 1 to M and calculate-return the sum of the expression.

- Inside the <em>test_sum_1k(),</em> calculate the <em>expected_value,</em> refers to the value that is calculated by hand and <em>computed_value,</em> refers to the value that is the result of the <em>sum_1k(3). </em>Then, compare the values and print the appropriate message

- Call the <em>test_sum_1k()</em> to see the result

You might be interested in
Susan has been hoping to get into her favorite college and has extended her study hours late into the night. Which of the follow
Otrada [13]

Answer:

She might feel really fatigued or stressed.

Explanation:

When you don't sleep before an exam it makes very tired and even more stressed than you might have been if you didn't study as much and did get a good night of sleep. Hope this helps :)

4 0
3 years ago
#include
Artist 52 [7]

Answer:

#include <iostream>

#include <vector>

using namespace std;

int main() {

const int NUM_VALS = 4;

vector<int> testGrades(NUM_VALS);

int i = 0;

int sumExtra = -9999; // Assign sumExtra with 0 before your for loop

testGrades.at(0) = 101;

testGrades.at(1) = 83;

testGrades.at(2) = 107;

testGrades.at(3) = 90;

/* Your solution goes here */

sumExtra = 0;

for(i = 0; i <= testGrades.size() -1; i++){

   if(testGrades.at(i) > 100){

       sumExtra = sumExtra + (testGrades.at(i) - 100);

   }

}

cout << "sumExtra: " << sumExtra << endl;

return 0;

}

Explanation:

Looks like you almost solved the question. I highlighted the parts you have been missing above.

In order to use vectors in C++, you need to add the vector library at the beginning of the program, #include <vector>

In order to initialize the vector, you need to specify its type inside <int>, since we work with the integers in the question the type must be <em>int</em>

3 0
3 years ago
Answer ASAP and I'll give brainliest, thanks, and five stars!
Goshia [24]

Answer:

The students who buy lunch are not getting enough time to socialize/ eat lunch because they spent it standing in line

Explanation:

That would be my guess, hope this helps

8 0
3 years ago
Read 2 more answers
Select the correct answer. What is the purpose of preserving historical data? A. legal compliance B. recruitment C. leave sancti
Gre4nikov [31]

Answer:The main goal of data preservation is to protect data from being lost or destroyed and to contribute to the reuse and progression of the data.

Explanation:

8 0
3 years ago
1) Limitations imposed by scientific principles or limited resources are called?
STALIN [3.7K]
D because it has limitations or <em><u>constraints</u></em><u /> 
D again because communication technology is used for all of these things.
Sender, Message, Receiver, Feedback
It can cause the system to conform to situations.
If they don't know the properties then they could damage their equipment or the project by misusing it.
Solids, Liquids, Gasses, Plasma, and Bose-Einstein condesates

5 0
3 years ago
Other questions:
  • One main advantage of CD-ROMs is that..
    7·1 answer
  • You were fortunate to get the ice off of the wings, but whatever caused the cabin to depressurize also vented all of your fuel o
    11·1 answer
  • The sales management team requires that the Lead Source field of the Lead record be populated when a Lead is converted. What wou
    9·1 answer
  • Can you tell me what is rast
    5·1 answer
  • Which statement is true of Web-based social media?
    12·1 answer
  • What is wrong with the formula below? SUM(A1:A5)/SUM(B1:B5)
    14·2 answers
  • Write a program that keeps track of a simple inventory for a store. While there are still items left in the inventory, ask the u
    12·2 answers
  • Fill in the blank with the correct response.
    14·1 answer
  • Sistem komponen mekanikal yang terdapat pada sebuah basikal?​
    13·1 answer
  • How should excel Identify social security numbers: as a text, numbers, or date and time? Why?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!