Question

volume_per_container python help

Imagine that a company in the freight transport business has commissioned you to solve the following problem. Given bulk cargo with a certain weight per m3, compute the volume of that bulk cargo in m3 that a single 40-foot standard container can hold.

A standard 40-foot container:
has an internal volume of 67.5 m3
a maximum net load of 26199 kg .
For instance, 1 m3 of gravel weighs 1800 kg. Because the maximum net load of a container is 26199 kg, a single container can only hold 14.555 m3 of gravel, otherwise it would exceed the maximum net load.
For comparison, 1 m3 of wood chips weighs 380 kg. Because the maximum net load of a container is 26199 kg, based on the maximum weight, it is allowed to hold 68.94 m3 of wood chips. However, the internal volume of a single container is only 67.5 m3, so a single container can hold 67.5 m3 of wood chips.
In answer to this question you will need to decompose the problem, write an algorithm, and implement the algorithm as a single python function that returns the total volume that can be held by single container.

i.Include your initial decomposition of the problem in your solution document using the chevron notation (> and >>)

ii.Include the algorithm for solving the problem in your solution document.

Part iii of this question involves writing one Python function definition. 

—— Draft Code——
def volume_per_container(kg_cargo_per_cubic_metre):
    """Given the kg of cargo per cubic metre, calculate how many cubic metres of cargo can be stored in a single container."""

    # INSERT YOUR CODE BELOW FOR CALCULATING THE 
    # TOTAL WEIGHT AND RETURNING THE RESULT (DO NOT CHANGE
    # THE HEADER OF THE FUNCTION WHICH HAS BEEN PROVIDED FOR YOU
    # ABOVE)
    
# DO NOT CHANGE THE CODE BELOW 
# The code below automatically tests your function
# If you run this file before making any changes to
# it, you will get an AssertionError. 
# Once you have completed the file with correct
# code, the AssertionError should no longer appear and
# message "tests passed" will appear in the shell.

def test_volume_per_container():
    """Test the volume_per_container function."""

    # Test for gravel at 1800 kg per cubic metre 
    assert volume_per_container(1800) == 14.555
    
    # Test for wood chips at 380 kg per cubic metre
    assert volume_per_container(380) == 67.5
    
    print ("tests passed") 
  
test_volume_per_container()
——— End Draft Code————

Write your Python function definition for volume_per_container() in the draft code where indicated.
Note that the Draft Code already contains code for automatically testing the function volume_per_container(). You must not change this code. 

iv. Provide a Python function that implements the algorithm. Follow the instructions above for submitting code.
Your answer must be a translation of your algorithm from part  (ii) above


0 0
Add a comment Improve this question Transcribed image text
Answer #1
def volume_per_container(weight):
   max_net_load=26199   #the maximim load of the container
   internal_volume=67.5   #the maximum volume of the container
   volume=max_net_load/weight   #calculating the volume bases on the weight of 1 m3
   if volume<=internal_volume:   #if volume less than the internal volume
       return volume    #return the calculated volume
   else:   #if volume is greater than the internal volume
       return internal_volume   #return the internal volume
def test_volume_per_container():
   """Test the volume_per_container function."""
   # Test for gravel at 1800 kg per cubic metre
   assert volume_per_container(1800) == 14.555
  
   # Test for wood chips at 380 kg per cubic metre
   assert volume_per_container(380) == 67.5
  
   print ("tests passed")

test_volume_per_container()


answered by: tesla
Add a comment
Know the answer?
Add Answer to:
volume_per_container python help
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CAN SOMEONE PLEASE HELP AND ANSWER THIS Introduction to computing and IT question --------------------------------------...

    CAN SOMEONE PLEASE HELP AND ANSWER THIS Introduction to computing and IT question ---------------------------------------------------------------------------------------------------------------------------------------------------------------- this is the file required for the question Question 4 (14 marks) This question assesses Block 2 Part 4 a. This part of the question involves creating two drawings. You can make your drawings whichever way is easiest or fastest for you. For instance, you could simply make your drawings using pencil and paper then scan or photograph them. Consider the following two assignments: o languages-['java',...

  • I need a python 3 help. Please help me with this question Part 2. Linked Lists...

    I need a python 3 help. Please help me with this question Part 2. Linked Lists You start working with the class LinkNode that represents a single node of a linked list. It has two instance attributes: value and next. class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Before you start with the coding questions, answer the following questions about the constructor Valid Constructor or Not? LinkNode(1, 3) LinkNode(1, None) LinkNode(1,...

  • Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me e...

    Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me errors. Thanks in advance!! This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. (2 pts) item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of...

  • Requires Python to answer A client wishes to keep track of his investment in shares. Write...

    Requires Python to answer A client wishes to keep track of his investment in shares. Write a program to help him manage his stock portfolio. You are to record both the shares that he is holding as well as shares that he has sold. For shares be is curreatly holding, record the following data: .a 3-character share code, share name, last purchase date, volume currently held and average purchase price (refer to description under part cii) option 2) For shares...

  • PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and...

    PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and my code for bag.cpp. Also I have provided errors from linux for bag.cpp. Please use that code and fix my errors please. Thank you The goal of assignment 3 is to reinforce implementation of container class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative...

  • Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a...

    Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a single string as input. This string is the name of the input directory. It returns a dictionary. This dictionary has keys that are the names of the individual input files. The dictionary values are the number of words in that file that have adjacent vowels ('aa', 'ae', 'oo', 'ia', etc.). Use a regular expression to find these, do not hard code every possible combination...

  • Recursion and Trees Application – Building a Word Index Make sure you have read and understood...

    Recursion and Trees Application – Building a Word Index Make sure you have read and understood ·         lesson modules week 10 and 11 ·         chapters 9 and 10 of our text ·         module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT