Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Language: Python Program used: PyCharm Interpreter: 3.6.1 at ~/anaconda/bin/pyth

ID: 3871029 • Letter: L

Question

Language: Python

Program used: PyCharm

Interpreter: 3.6.1 at ~/anaconda/bin/python

Question 4 (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 drivee 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 - 2048.0 # capacity of hard drive in GB applications_percent-321.0/2048.0 100.0 documents_percent-46.0/2048.0 100.0 media-percent = 899.0/2048.0 * 100.0 free percent 782.0/2048.0100.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 (321.0 GB) "is occupied by applications.") " is occupied by document files." "is occupied by multimedia files.") print (str (documents-percent)+"% of hard drive space (46.0 GB)"+ print (str(media-percent ) +" % of hard drive space (899.0 GB)"+ 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 diferent 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 new parameter values. Also modify the docstring to describe the new parameters (currently none). The above function is already provided for you in a2q4-starter.py, so you don't have to re-write it. You should demonstrate that your new version of the function produces the same output for every parame- ter introduced. That is, if you were to call your new function using print disk_quota (2048.0,321.0,46.0,899.0) you should wind up with the exact same output as the starter code What to Hand In Hand in your solution in a file called a2q4.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

Explanation / Answer

Given Code and its execution


def print_disk_quota():
    capacity = 2048.0
    applications_percent = 321 / 2048.0 * 100.0
    documents_percent = 46.0 / 2048.0 * 100.0
    media_percent = 899.0 / 2048 * 100.0
    free_percent = 782.0 / 2048 * 100.0

    print("you have " + str(free_percent)+ "% of " + str(capacity)+ " GB free." )
    print(str(applications_percent)+ "% of hard drive space (321.0 GB) is occupied by applications.")
    print(str(documents_percent)+"%of hard drive space (46.0 GB) is occupied by document files.")
    print(str(media_percent)+"% of hard drive space (899.0 GB) is occupied by multimedia files.")

print_disk_quota()


'''

output
------
you have 38.18359375% of 2048.0 GB free.
15.673828125% of hard drive space (321.0 GB) is occupied by applications.
2.24609375%of hard drive space (46.0 GB) is occupied by document files.
43.896484375% of hard drive space (899.0 GB) is occupied by multimedia files.
>>>
'''


==============================
Asked code and its execution
===============================
def print_disk_quota(c,a,d,m):
    capacity = c
    applications_percent = a / c * 100.0
    documents_percent = d /c * 100.0
    media_percent = m / c * 100.0
    free_percent = 782.0 / c * 100.0

    print("you have " + str(free_percent)+ "% of " + str(capacity)+ " GB free." )
    print(str(applications_percent)+ "% of hard drive space (" + str(a) + " GB) is occupied by applications.")
    print(str(documents_percent)+"%of hard drive space ("+ str(d) +" GB) is occupied by document files.")
    print(str(media_percent)+"% of hard drive space (" + str(m) + " GB) is occupied by multimedia files.")

print_disk_quota(2048.0,321.0,46.0,899.0)   

'''
output
------
you have 38.18359375% of 2048.0 GB free.
15.673828125% of hard drive space (321.0 GB) is occupied by applications.
2.24609375%of hard drive space (46.0 GB) is occupied by document files.
43.896484375% of hard drive space (899.0 GB) is occupied by multimedia files.
'''