Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1.  
  2. def amount_of_plastic(width_brick, height_brick, length_brick, number_of_bricks):
  3. """Given the dimensions of a brick (width, height, length in cm) and the number of bricks ordered, calculate how much plastic, in grams, is required (if a cubic centimetre weighs 7 grams)."""
  4.  
  5. # INSERT YOUR CODE BELOW THIS LINE FOR CALCULATING THE
  6. # AMOUNT OF PLASTIC AND RETURNING THE RESULT (DO NOT CHANGE
  7. # THE HEADER OF THE FUNCTION WHICH HAS BEEN PROVIDED FOR YOU
  8. # ABOVE)
  9.  
  10.  
  11. #calculate the volume of brick
  12.  
  13. length_brick = int(input('Please Enter the Length of a Brick: '))
  14. width_brick = int(input('Please Enter the Width of a Brick: '))
  15. height_brick = int(input('Please Enter the Height of a Brick: '))
  16. number_of_bricks = int(input('Please Enter the Number of Bricks: '))
  17. grams = 7
  18.  
  19. #calculate grams needed for ordered bricks
  20.  
  21. amount_of_plastic = (width_brick* height_brick* length_brick* number_of_bricks) * grams
  22.  
  23. print ('Amount of plastic need for you order is ', amount_of_plastic, 'grams.')
  24.  
  25.  
  26. # DO NOT CHANGE THE CODE BELOW THIS LINE
  27. # The code below automatically tests your function
  28. # following the approach described in
  29. # Block 2 Part 4 (Page 207 and further).
  30. # Before making any changes to this file,
  31. # when you run it, you will get an AssertionError.
  32. # Once you have completed the file with correct
  33. # code, the AssertionError should no longer appear and
  34. # "tests passed" will appear in the shell.
  35.  
  36.  
  37. def test_amount_of_plastic():
  38. """Test the amount_of_plastic() function."""
  39. # Test for brick with dimensions 0, 0, 0 and
  40. # order of 20 bricks
  41. assert amount_of_plastic(0, 0, 0, 20) == 0
  42.  
  43. # Test for brick with dimensions 1, 1, 1 and
  44. # order of 0 bricks
  45. assert amount_of_plastic(1, 1, 1, 0) == 0
  46.  
  47. # Test for brick with dimensions 1, 1, 1 and
  48. # order of 20 bricks
  49. assert amount_of_plastic(1, 1, 1, 20) == 140
  50.  
  51. # Test for brick with dimensions 1, 2, 3 and
  52. # order of 100 bricks
  53. assert amount_of_plastic(1, 2, 3, 100) == 4200
  54.  
  55. print ("tests passed")
  56.  
  57.  
  58. test_amount_of_plastic()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement