Files
Laboratori-PY/Laboratorio10/vendite.py
2024-03-22 17:01:42 +01:00

30 lines
552 B
Python

from sys import exit
def main():
try:
fio = open("vendite.txt", "r")
except FileNotFoundError:
exit("File not found")
datas = {}
for line in fio:
data = line.split(";")
if len(data) != 4:
exit("Invalid line: " + line)
service = data[1].strip()
cost = float(data[2].strip())
if service not in datas:
datas[service] = 0
datas[service] += cost
for key in datas:
print(key + ":", datas[key])
fio.close()
main()