Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hey smart, I need your kindly help for these questions, please run them in python~ I am looking forward to receiving your answer :) This
Hey smart, I need your kindly help for these questions, please run them in python~ I am looking forward to receiving your answer :)
This question is a simple variant of the print_daily_totals function you wrote earlier, except that now you are expected to write the output to a file, the name of which is passed as a second parameter. Specifically: write a function generate_daily_totals(input_filename, output_filename) that reads the named input file (which consists of a date in ISO 8601 format followed by one or more floating point numbers, all separated by commas). For each line in the input file, your function should write to the named output file a summary line of the form formatted date = total, with the total given to 2 decimal places. For example, if a file blahin.txt contains the two lines 2010-01-01, 10.00,20.0 2010-01-02, 12.00,100.1,3.2 then a call to generate_daily_totals("blahin.txt", "blahout.txt") would result in the creation of a file blahout.txt containing the two lines 01 Jan 2010 = 30.00 02 Jan 2010 = 115.30 Note: You can use the data files provided for the print_daily_totals question when testing your code. Note: You can use the data files provided for the print_daily_totals question when testing your code. For example: Test Result generate_daily_totals('data90.txt', 'totals90.txt') 10 Apr 2006 1399.46 checker = open('totals90.txt') 11 Apr 2006 2822.36 print(checker.read()) 12 Apr 2006 = 2803.81 checker.close() 13 Apr 2006 = 1622.71 14 Apr 2006 = 3119.60 15 Apr 2006 = 2256.14 16 Apr 2006 = 3120.05 20 Apr 2006 = 1488.00 generate_daily_totals('data91.txt', 'totals.txt') checker = open('totals.txt') print("Summary:") print(checker.read()) checker.close() Summary: 17 Sep 2001 = 4071.00 25 Sep 2001 1107.60 30 Oct 2002 = 4554.94 Python programs are saved as ordinary text files (with the extension.py). This means we can read them and process them just like any other data file. Write a function num_whiles(filename) that reads the Python program file with the given filename and returns a count of the number of while loops found in that program. More precisely, your function should return the number of lines starting with (possibly) some white space followed by the string while ', i.e. the word while with a space at the end. This is usually, but not necessarily, the same as the number of while loops in the program, but we won't worry about that here. In the first example below, the file testo.py contains the following program: i = 0 while iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started