Write a function called csv_sum that takes a filename and returns the sum of all of the numbers in the file. The numbers are in csv format. For instance, if the contents of the file are: 12,3,2 -5 10,20,-10,8.3 Then the function should return 40.3.

Answers

Answer 1

Answer:

Explanation:

def csv_sum(filename):

   total = 0

   try:

       f = open(filename)

       for line in f:

           words = line.strip().split(",")

           for word in words:

               total += float(word)

       f.close()

   except FileNotFoundError:

       pass

   return total


Related Questions

Write a program to implement problem statement below; provide the menu for input N and number of experiment M to calculate average time on M runs. randomly generated list. State your estimate on the BigO number of your algorithm/program logic. (we discussed in the class) Measure the performance of your program by given different N with randomly generated list with multiple experiment of Ns against time to draw the BigO graph (using excel) we discussed during the lecture.

Answers

Answer:

Explanation:

#include<iostream>

#include<ctime>

#include<bits/stdc++.h>

using namespace std;

double calculate(double arr[], int l)

{

double avg=0.0;

int x;

for(x=0;x<l;x++)

{

avg+=arr[x];

}

avg/=l;

return avg;

}

int biggest(int arr[], int n)

{

int x,idx,big=-1;

for(x=0;x<n;x++)

{

if(arr[x]>big)

{

big=arr[x];

idx=x;

}

}

return idx;

}

int main()

{

vector<pair<int,double> >result;

cout<<"Enter 1 for iteration\nEnter 2 for exit\n";

int choice;

cin>>choice;

while(choice!=2)

{

int n,m;

cout<<"Enter N"<<endl;

cin>>n;

cout<<"Enter M"<<endl;

cin>>m;

int c=m;

double running_time[c];

while(c>0)

{

int arr[n];

int x;

for(x=0;x<n;x++)

{

arr[x] = rand();

}

clock_t start = clock();

int pos = biggest(arr,n);

clock_t t_end = clock();

c--;

running_time[c] = 1000.0*(t_end-start)/CLOCKS_PER_SEC;

}

double avg_running_time = calculate(running_time,m);

result.push_back(make_pair(n,avg_running_time));

cout<<"Enter 1 for iteration\nEnter 2 for exit\n";

cin>>choice;

}

for(int x=0;x<result.size();x++)

{

cout<<result[x].first<<" "<<result[x].second<<endl;

}

}

4. Write a program to calculate square root and
cube root of an entered number .​

Answers

Answer:

DECLARE SUB SQUARE (N)

CLS

INPUT “ENTER ANY NUMBER”; N

CALL SQUARE(N)

END

SUB SQUARE (N)

S = N ^ 2

PRINT “SQUARE OF NUMBER “; S

END SUB

Select the correct term to complete the sentence.
The
file format is used for video files.

A. .pptx

B. .mp3

C. .jpeg

D. .mp4

Answers

Answer: D. mp4

its mp4 because its always on video files

Which of the following is true? a. There are RFCs that describe challenge-response authentication techniques to use with email. b. Filtering for spam sometimes produces a false positive, in which legitimate email is identified as spam. c. Spam relies heavily on the absence of email authentication. d. All of the above.

Answers

The option that is true is option b. Filtering for spam sometimes produces a false positive, in which legitimate email is identified as spam.

How is spam filtration carried out?

The processing of email to organize it in accordance with predetermined criteria is known as email filtering. The word can allude to the use of human intelligence, although it most frequently describes how messages are processed automatically at SMTP servers, sometimes using anti-spam tactics.

Therefore, Email filtering operates as previously stated by scanning incoming messages for red flags that indicate spam or phishing content and then automatically transferring such messages to a different folder. Spam filters evaluate an incoming email using a variety of criteria.

Learn more about Filtering for spam from

https://brainly.com/question/13058726
#SPJ1

Other Questions
Which civilization was the first to adopt Democracy as a form of government? A Greek B. Roman C. Persian D. Egyptian Help plzzzzzz 1. Use your expression from Exercise 15 to find the total cost of 8 play tickets and 8 choir concert ticketsexercise 15 is Rory buys t play tickets at $14.50 per ticket and t choir concert ticketsat $5.50 per ticket. What is the cost for play tickets and choir concerttickets?plz help Mrs. Wigen conducted a survey in her math class. She asked each of her students to tell her how many pets they have at home. The dot plot below represents the results of Mrs. Wigen's math class survey. 12-----3 4:25 Number of pets at home Find the Measures of Center for the data: Mean Round to the nearest tenths place Median Mode Line m is represented by the equation below. Select all equation that represent lines perpendicular to line m. Dr. Martinez is curious as to whether exposing people to violent video games causes them to be more aggressive. He assigns half his participants to play a video game for 5 minutes and the other half to play for 7 minutes. He finds that there is no relationship between playing the game longer and being more aggressive. What might be to blame for this null effect During one month, there were 2,000 people who used the advertiser links on a website. The percent of people who clicked on eachadvertisement link is shown in the circle graph. Calculate the number of people who clicked on the link for each type of advertisement. Howmany people used the Music link?Advertiser LinksComputers2396Music25%TVS3%Movies1796Cell phones32%340450500540 which model shows 9 (3+6) = (9 x 3) + (9 x 6)?NO LINKS OR FILES THANK YOU!! 3. Svante Arrhenius developed a definition of acids and baseswhich stated...A. acids produce OH+ ions and bases produce H ionsB. acids produce H+ ions and bases produce OH ionsSTATC. acids and bases are the sameD. acids have a high pH and bases have a low pHpls help btw any links will be reported. HELP!!!!!!!!!The Consumer Bill of Rights says that you have the right to safety. This means _____________. you are protected from misleading advertising by being able to ask for the facts to make a good decision you are protected from dangerous products you can make your own decisions you can speak out if you are not satisfied Find X and angles R and L. Please help me with this The U.S Constitution is considered a milestone in the protection of individual rights, but it is by no means perfect. What is currently lacking in the Constitution? How should those changes be made - through court decisions, or by amendments?? Given circle Q a measure of SR = 120 degree and a radius of 9 feet, as shown below determine the arc length of SR use mathematics to explain how you determined your answer. Volume and circles Help please In your OWN words, what is the difference between a solute, solvent and solution? In response to dwindling sales of organic meats, Hain Celestial executives decided to promote the sale of organically grown nuts as an alternative source of protein, which is an excellent example of a firm's: HELPPPPPPsolve the equation for x2/3x-1/9x+5=20 Without looking, Tammy takes a marble out of a bag that contains 10 red marbles, 15 green marbles, and 25 blue marbles. She records its color and returns the marble to the bag. If Tammy repeats this process 90 times, how many times can she expect to pull out a red marble? A gas occupies 4.21 Iiters at a pressure 1 074 atm. What will its volume be if the pressure is decreased to 0.46 atm? Read the following paragraph.Macy was nervous. She had never attended such a formal dinner before. People were speaking in low voices. The matching plates, bowls, glasses, and cutlery were laid out perfectly. Macy had no idea which of the two forks she needed to use first. Dinner at her house was always relaxed with everyone talking and laughing loudly about the events of the day. Most of the time their plates didnt even match, and the napkins were always made of paper. Macy took the cloth napkin and placed it on her lap, just like she had just seen her friend do. So far, so good. Hopefully, she could copy her friend for the rest of dinner.Use the context clues to find the definition for the word formal as it is used in this paragraph.a-properb-expensivec-lengthyd-deliciousFOR BRAINLIST what was the first name of the first english settlement in new england The ratio x:y is 1:3Which of the following statements are correct?A. x is 1/3 of yB. y is 2 of (x + y)C x is 1/4 of yD. y is 3/4 of x