-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoit-algo-04_01.py
More file actions
31 lines (22 loc) · 933 Bytes
/
goit-algo-04_01.py
File metadata and controls
31 lines (22 loc) · 933 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
29
30
import re
from pathlib import Path
def total_salary(path):
try:
with open(path) as file:
file_text = file.read()
print(file_text)
pattern = r"\d+"
salary = re.findall(pattern, file_text)
salary_int = list(map(int, salary))
total = sum(salary_int)
average = int(total/ len(salary_int)) if len(salary_int) > 0 else 0
except FileNotFoundError:
print('file not found')
#return None, None
except Exception as e:
return None, None
return total, average
total, average = total_salary(r"path/to/salary_file.txt")
print(f"Загальна сума заробітної плати: {total}, Середня заробітна плата: {average}")
# if total is not None and average is not None:
# print("Error occurred.")