Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 3 (10 points): Purpose: To generalize an existing function so that it can perform a wider range of subtasks. Degree of Difficulty: Moderate Function

image text in transcribedimage text in transcribed

Question 3 (10 points): Purpose: To generalize an existing function so that it can perform a wider range of subtasks. Degree of Difficulty: Moderate Function print_disk_quota displays the amount of space in gigabytes (GB) and percentage of space that specific file types occupy on a hard drive: def print_disk_quota(): Displays (to console) the amount of space in GB and percentage of space that major file types occupy on the hard drive as well as the amount of space free/available for use. I! ! ! # calculate percentage of space occupied by certain file types capacity = 1024.0 # capacity of hard drive in GB media-percent = 365.0/1024.0 * 100.0 # percentage of hard drive occupied # by multimedia files documents_percent = 10.0/1024.0 * 100.0 # percentage of hard drive occupied # by document files applications-percent = 425.00/1024.0 + 100.0 # percentage of hard drive occupied # by applications free-percent = 224.0/1024.0 * 100.0 # percentage of hard drive available # print disk quota to console print("You have " + str (free-percent)+"% of "+str(capacity)+" GB free.") print (str (media_percent)+"% of hard drive space (365.0 GB)"+ " is occupied by multimedia files.") print (str(documents_percent)+"% of hard drive space (10.0 GB)"+ " is occupied by document files.") print (str(applications-percent)+"% of hard drive space (425.0 GB)" + " is occupied by applications.") Recall that the generalization of a function is the process of revising a function to solve a wider range of problems. Generalize this function by converting appropriate literal values in the function into parameters so that it can print the disk quota usage for different hard drive capacities and different amounts of space used by each file type. You may have to modify multiple lines of the function body to accommodate for a new parameter value. Also modify the docstring to describe the new parameters. The above function is already provided for you in a2q3-starter.py, so you don't have to re-write it. You should test that the function produces the same output for every parameter introduced. That is, if you give the function the same specific inputs used in the starter code as arguments for your new parameters, you should wind up with the same output in both scenarios. What to Hand In Hand in your solution in a file called a2q3.py. Evaluation 2 marks for generalizing the hard drive capacity as a parameter. 6 marks for generalizing each of the three file types' space usage as a parameter (2 marks per file type parameter). 2 marks for appropriate modifications to the docstring -1 mark if identifying information (name, NSID, student number and instructor's name) is missing # CMPT 141 a2q4 # Starter Code def print_disk_quota(): Displays (to console) the amount of space in GB and percentage of space that major file types occupy on the hard drive as well as the amount of space free/available for use. # calculate percentage of space occupied by certain file types capacity = 4096.0 # capacity of hard drive in GB applications_percent = 586.0 / 4096.0 * 100.0 documents_percent = 125.0 / 4096.0 * 100.0 media_percent = 1015.0 / 4096.0 * 100.0 free_percent = 2370 / 4096.0 * 100.0 # print disk quota to console print("You have "+str(free_percent)+"% of "+str(capacity)+" GB free.") print (str(applications_percent)+"% of hard drive space (586.0 GB) is occupied by applications.") print (str(documents_percent)+"% of hard drive space (125.0 GB) is occupied by document files.") print(str (media_percent)+"% of hard drive space (1015.0 GB) is occupied by multimedia files.") # testing function print_disk_quota() # after you make your changes, the following function call should work instead: # print_disk_quota(4096.0,586.0,125.0,1015.0)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions