-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_from_file.py
More file actions
55 lines (45 loc) · 1.22 KB
/
calc_from_file.py
File metadata and controls
55 lines (45 loc) · 1.22 KB
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
47
48
49
50
51
52
53
54
55
def perform_calc(operation, intA, intB):
if operation == 'x':
return int(intA) * int(intB)
elif operation == '+':
return int(intA) + int(intB)
elif operation == '-':
return int(intA) - int(intB)
elif operation == '/':
return int(intA) / int(intB)
else:
return ('Invalid Operation Specified: ' + operation)
def read_file():
with open ("step_2.txt", 'r') as f:
lines = f.read().splitlines()
return lines
def step2():
lines = read_file()
result = 0
for line in lines:
tuple = line.split()
result += perform_calc(tuple[1], tuple[2], tuple[3])
print(result)
def step3():
file = read_file()
lines = set()
line_count = 0
for line in file:
line_count+=1
tuple = line.split()
if(str(tuple) in lines):
print("Duplicate line at: " + str(line_count))
break
lines.add(str(tuple))
if len(tuple) > 2:
next_line = perform_calc(tuple[2], tuple[3], tuple[4])
else:
next_line = tuple[1]
# run step 2
print("Step2 starting")
#step2()
print("Step2 completed")
# run step 3
print("Step3 starting")
step3()
print("Step3 completed")