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]
2 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]2 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
Where is the risk of someone intercepting another person’s online activity the greatest?
sergey [27]

social networking site

3 0
3 years ago
How many days has trump been a president
Free_Kalibri [48]
Hey there
_______________
The correct answer is
1 year, 64 days, 13 hours, 11 minutes and 44 seconds

__________
Hope this helps you
8 0
3 years ago
Read 2 more answers
Please help!!!
Alchen [17]

The most probable reason why your code for the dog turning right instead of is because your conditional statements are not satisfied.

<h3>What is Debugging?</h3>

This refers to the identification and removal of errors in a given code or hardware component.

Hence, we can see that you should note that you are using teh ifElse conditional statement to execute your code and you stated that the dog would turn right if:

  1. The left side is blocked
  2. If there are balls present.

Therefore, there are balls present and also the left side is blocked which causes your dog to turn right because it is executing the else statement.

Read more about debugging here:

brainly.com/question/16813327

#SPJ1

6 0
2 years ago
Instructions
e-lub [12.9K]

Answer:

See explaination

Explanation:

dateType.h

#ifndef dateType_H

#define dateType_H

class dateType

{

public:

void setDate(int month, int day, int year);

//Function to set the date.

//The member variables dMonth, dDay, and dYear are set

//according to the parameters.

//Postcondition: dMonth = month; dDay = day;

// dYear = year

int getDay() const;

//Function to return the day.

//Postcondition: The value of dDay is returned.

int getMonth() const;

//Function to return the month.

//Postcondition: The value of dMonth is returned.

int getYear() const;

//Function to return the year.

//Postcondition: The value of dYear is returned.

void printDate() const;

//Function to output the date in the form mm-dd-yyyy.

void isLeapYear() const;

dateType(int month = 1, int day = 1, int year = 1900);

//Constructor to set the date

//The member variables dMonth, dDay, and dYear are set

//according to the parameters.

//Postcondition: dMonth = month; dDay = day; dYear = year;

// If no values are specified, the default

// values are used to initialize the member

// variables.

private:

int dMonth; //variable to store the month

int dDay; //variable to store the day

int dYear; //variable to store the year

};

#endif

dateType.cpp

#include <iostream>

#include "dateType.h"

using namespace std;

void dateType::setDate(int month, int day, int year)

{

// Checking month is valid

while(month<1 || month>12)

{

cout << "Enterd month "<<month<< " is wrong"<<endl;

cout << "Enter correct month"<<endl;

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day<1 || day>31)

{

cout << "Enterd date "<<day<<" is wrong"<<endl;

cout<<"Enter correct date"<<endl;

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout << "Enterd year "<<year1<<" is wrong"<<endl;

cout<<"Enter correct year"<<endl;

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

cout << dMonth << "-" << dDay << "-" << dYear;

}

void dateType::isLeapYear() const

{

if ( dYear%400 == 0)

cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%100 == 0)

cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%4 == 0 )

cout<<endl<<dYear<< " is leap year.\n";

else

cout<<endl<<dYear<< " is not leap year.\n";

}

//Constructor with parameters

dateType::dateType(int month, int day, int year)

{

// Checking month is valid

while(month<1 || month>12)

{

cout << "Enterd month "<<month<< " is wrong"<<endl;

cout << "Enter correct month"<<endl;

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day<1 || day>31)

{

cout << "Enterd date "<<day<<" is wrong"<<endl;

cout<<"Enter correct date"<<endl;

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout << "Enterd year "<<year1<<" is wrong"<<endl;

cout<<"Enter correct year"<<endl;

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

main.cpp

#include<iostream>

#include "dateType.h"

using namespace std;

int main()

{

dateType *dt1=new dateType();

cout<<"Date is "<<endl;

dt1->printDate();

cout<<endl;

dt1->isLeapYear();

cout<<endl;

dateType *dt2=new dateType(11,14,2019);

cout<<"Date is "<<endl;

dt2->printDate();

cout<<endl;

dt2->isLeapYear();

cout<<endl;

dt2->setDate(13,32,2016);

cout<<"Date is "<<endl;

dt2->printDate();

cout<<endl;

dt2->isLeapYear();

cout<<endl;

dt1->setDate(10,10,198);

cout<<"Date is "<<endl;

dt1->printDate();

cout<<endl;

dt1->isLeapYear();

cout<<endl;

system("pause");

return 0;

}

6 0
3 years ago
A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost
makvit [3.9K]

Answer:

milk_produced = float(input("Enter the total amount of milk produced in the morning: "))

liter_cost = float(input("Enter the cost of producing one liter of milk: "))

carton_profit = float(input("Enter the profit on each carton of milk: "))

carton_needed = round(milk_produced / 3.78)

cost = milk_produced * liter_cost

profit = carton_profit * carton_needed

print("The number of milk cartons needed to hold milk is " + str(carton_needed))

print("The cost of producing milk is " + str(cost))

print("The profit for producing milk is " + str(profit))

Explanation:

*The code is in Python.

Ask the user to enter milk_produced, liter_cost and carton_profit

Calculate the number of milk cartons needed, divide the milk_produced by the capacity (3.78) of a cartoon and round the result

Calculate the cost, multiply the milk_produced by liter_cost

Calculate the profit, multiply the carton_profit by carton_needed

Print the results

3 0
3 years ago
Other questions:
  • The publisher tab in the application control allows you to manage the various certificates that are used to do what to binaries?
    8·1 answer
  • Different organizations implement different Information Systems base on their core business operations. explain
    14·1 answer
  • A group of computers that are interconnected in order to share information or documents is called a _____.
    7·1 answer
  • Unlike memory, this type of storage holds data and programs even after electrical power to the computer system has been turned o
    10·1 answer
  • Text that is heavier or darker than other text in the document is considered _____.
    9·2 answers
  • When planning your website, what is one of the key things you should consider
    12·2 answers
  • The physical elements needed for the production of digital media, such as computers, servers, and so on are called the {Blank}
    8·1 answer
  • WILL GIVE BRAINLIEST!!!!!
    8·1 answer
  • Which terms means device that converts one voltage to another ?
    15·1 answer
  • ____________ are the in – built functions that perform a particular pre – defined task when used in a computer program.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!