Question

Delivery truck drivers are consigned various cargo each day. You are tasked to write a program that calculates the weight of
$ python3 truck.py cargo.txt 3000.00 wardrobe: 550.30kg mattress: 300.10kg fauteuil: 600.00kg drawer: 1230.55kg hammock: 75.0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import sys
import csv

# read command line arguments
filename = sys.argv[1]
maxload = float(sys.argv[2])

# open csv file from current folder with file name
with open(filename) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
totalweight = 0
# read each row and entries and print it
for row in csv_reader:
print(f'\t{row[0]} : {row[1]} Kg')
line_count += 1
totalweight += float(row[1])

print("Total weight :", totalweight)

#cheack if totalweight is below permited limited or not
if (totalweight < maxload):
print ("Success! Cargo has been loaded")
else:
print ("Hold On!! Cargo is Overloaded")

- D x weighttest.py - E:\HomeworkLibCode weighttest.py (3.8.2) File Edit Format Run Options Window Help import sys import csv filen

Add a comment
Know the answer?
Add Answer to:
Delivery truck drivers are consigned various cargo each day. You are tasked to write a program...
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
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