a6q2 - # CS116 Assignment 6 Question 2 # Ru Wang r46wang...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
## CS116 Assignment 6 Question 2 ## Ru Wang r46wang 20319247 ## needed_discs: int (union int float) int[0:100] int[>0] -> int[>0] ## Purpose: needed_discs calculates the number of discs required to store all pictures on discs. ## It consumes an integer for the number of pictures to store, a file size of each picture in either integer or float, a compression rate that is an integer between 0 and 100, and the size of the one disc in a positive integer. ## It returns an integer indicating how many discs are required to store all of the pictures. ## Examples: ## needed_discs(0, 3, 0, 100) => 0 ## needed_discs(100, 3, 0, 700) =>1 ## needed_discs(100, 2.5, 0, 700) => 1 ## needed_discs(100, 3, 100, 700) => 0 ## needed_discs(100, 3, 0, 100) =>4 ## needed_discs(100, 2, 25, 700) => 3 def needed_discs(num_pics, pic_size, comp_rate, disc_size): if num_pics == 0 or comp_rate == 100: return 0 per_disc = int (disc_size / (pic_size * (100 - comp_rate) / float(100))) remain = num_pics % per_disc if remain == 0:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

a6q2 - # CS116 Assignment 6 Question 2 # Ru Wang r46wang...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online