15,672,515 members
See more:
The manager of a building materials delivery service needs a program to check the contents and weight
of sacks to ensure that correct orders are made up for delivery. A price for the order will be calculated.

Write and test a program for the manager.
• Your program must include appropriate prompts for the entry of data.
• Error messages and other output need to be set out clearly.
• All variables, constants and other identifiers must have meaningful names.

You will need to complete these three tasks. Each task must be fully tested.
TASK 1 – Check the contents and weight of a single sack
Each sack must obey the following rules to be accepted:

• contain cement, gravel or sand, with a letter on the side for easy identification
o C - cement
o G - gravel
o S - sand

• sand or gravel must weigh over 49.9 and under 50.1 kilograms
• cement must weigh over 24.9 and under 25.1 kilograms

Input and store the weight and contents for one sack. The contents must be checked and an incorrect
sack rejected. The weight must be validated on entry and an overweight or underweight sack rejected.

Output the contents and weight of an accepted sack. If a sack is rejected, output the reason(s).

What I have tried:

Python
```Content = str(input("What is the content?"))

Content_sub1 = "C"

if Content_sub1 in Content :
Weight_ofc = float(input("What is the weight of the sack"))
if Weight_ofc < 49.9 :
print("The weight of the sac is too low")
elif Weight_ofc > 55 :
print("The weight of the sac is too high")
else: print(Content ,  Weight_ofc )
else : print("the sack is invalid")

Content_sub2 = "G"

if Content_sub2 in Content :
Weight_ofg = float(input("What is the weight of the sack"))
if Weight_ofg < 49.9 :
print("The weight of the sac is too low")
elif Weight_ofg > 55 :
print("The weight of the sac is too high")
else: print(Content ,  Weight_ofg )
else : print("the sack is invalid")

Conent_sub3 ="S"

if Conent_sub3 in Content :
Weight_ofs = float(input("What is the weight of the sack"))
if Weight_ofs < 24.9 :
print("The weight of the sac is too low")
elif Weight_ofs > 25.1 :
print("The weight of the sac is too high")
else: print(Content , Weight_ofs)
else : print("the sack is invalid")
```
Posted
Updated 17-Jan-21 22:43pm
v2
Dave Kreskowiak 17-Jan-21 20:21pm
You never said anything about a problem you're having, nor expressed a question.
Richard MacCutchan 18-Jan-21 4:31am

Solution 2

You could simplify your code considerably by writing a function to test the sack weight. Create a dictionary that contains the sack type as the key, and the weight limits as the value item. Something like:
Python
`sacks = { "C": [24.9, 25.1], "S": [49.9,50.1 ], "G": [49.9,50.1 ]}`

You can then pass the type and weight of the sack to the function for checking. The function can then use the sack type to get the lower and upper weights from a list and do the comparisons that way.

Dynam0 18-Jan-21 11:22am
thankyou richard, i will implement that on my code and use it. Regards
Richard MacCutchan 18-Jan-21 11:27am
You are welcome. Here is a link to the Python documentation on Dictionary usage: Built-in Types — Python 3.7.9 documentation[^].
Dynam0 18-Jan-21 11:44am
Richard, what type of function can i use
Richard MacCutchan 18-Jan-21 11:51am
You must write the function. And it should accept two parameters, the letter that identifies the sack type, and the weight in kilograms. You can then iterate through the dictionary looking for a matching letter (don't forget to convert it to upper case). The value entry on the matching letter gives you the limits for the weight. So you just need to compare the given weight with the two values to see if it is in that range.
Dynam0 18-Jan-21 12:50pm
okay, let me research more on that, at the moment i am abit lost

Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

Dynam0 18-Jan-21 9:33am
@OriginalGriff, thank you so much for trying to help me, and thankyou for leading me to the correct path. You are right, i should try and do it myself then when it is a problem i cannot solve at all i can post it, also thanks for linking the page as i am going to use it more often
OriginalGriff 18-Jan-21 9:57am
You're welcome!