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 filename = sys.argv[1] maxload = float (sys.argv[2]) with open (filename) as csv file: csv_reader = csv.reader (csv file, delimiter=',') line count = 0 totalweight = 0 for row in csv reader: print (f'\t{row[0]} : {row[1]} Kg') line count += 1 totalweight += float (row[1]) Customize weighttest.py Run X Command Line Arguments for sys.argv: cargo.txt 20000 print ("Total weight :", totalweight) Restart shell if (totalweight < maxload) : print ("Success! Cargo has been loaded") else: print ("Hold On!! Cargo is overloaded") D OK Cancel Python 3.8.2 Shell File Edit Shell Debug Options Window Help Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license ()" for more information. >>> ====================== RESTART: E:\HomeworkLibCode weighttest.py ==================== wardrobe : 550.30 Kg mattress : 300.10 kg fauteuil : 600.00 Kg drawer : 1230.55 kg hammock : 75.00 kg Total weight : 2755.95 Success! Cargo has been loaded >>> ================= RESTART: E:\HomeworkLibCode weighttest.py =========== wardrobe : 550.30 Kg mattress : 300.10 kg fauteuil : 600.00 Kg drawer : 1230.55 kg hammock : 75.00 Kg Total weight : 2755.95 Success! Cargo has been loaded >>>