forked from thedanfields/python-mastery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcost.py
More file actions
28 lines (19 loc) · 630 Bytes
/
Copy pathpcost.py
File metadata and controls
28 lines (19 loc) · 630 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
def portfolio_cost(filename):
file = open(filename)
entries = [line.strip().split() for line in file.readlines()]
valid_pairs = []
for entry in entries:
try:
valid_pairs.append((int(entry[1]), float(entry[2])))
except ValueError as e:
print("Failed to parse " + " ".join(entry))
print("Reason:", e)
return sum([item1 * item2 for item1, item2 in valid_pairs])
def main():
if len(sys.argv) < 2:
print("Must provide filename argument")
exit(1)
print(portfolio_cost(sys.argv[1]))
if __name__ == "__main__":
main()