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()