-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.py
50 lines (32 loc) · 968 Bytes
/
2.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
def safe_report_check(parts):
prev = None
desc = None
for part in parts:
if prev is None:
prev = part
continue
prev = int(prev)
part = int(part)
if (prev > part) and (desc == None or desc == True) :
if abs(prev - part) > 3:
return 0
desc = True
elif (prev < part) and (desc == None or desc == False):
if abs(prev - part) > 3:
return 0
desc = False
else:
return 0
prev = part
print(parts,'Safe')
return 1
folder_name = "P"
file_name = "2_p.txt"
file_path = os.path.join(folder_name, file_name)
safe_report_count = 0
with open(file_path, 'r') as file:
for line in file:
parts = line.strip().split(' ')
safe_report_count += safe_report_check(parts)
print(safe_report_count)