-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1b.py
More file actions
29 lines (24 loc) · 958 Bytes
/
Copy pathtask1b.py
File metadata and controls
29 lines (24 loc) · 958 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
# task1b
task1b_input = open(file='input1b.txt', mode='r')
task1b_output = open(file='output1b.txt', mode='w')
num_of_line = int(task1b_input.readline())
for i in range(num_of_line):
temp = task1b_input.readline().strip().split(" ")
if temp[2]== "+" :
add = int(temp[1]) + int(temp[3])
s = f"The result of {temp[1]} {temp[2]} {temp[3]} is {add}.\n"
task1b_output.write(s)
elif temp[2]== "-" :
sub = int(temp[1]) - int(temp[3])
s = f"The result of {temp[1]} {temp[2]} {temp[3]} is {sub}.\n"
task1b_output.write(s)
elif temp[2]== "*" :
mul = int(temp[1]) * int(temp[3])
s = f"The result of {temp[1]} {temp[2]} {temp[3]} is {mul}.\n"
task1b_output.write(s)
elif temp[2]== "/" :
div = int(temp[1]) / int(temp[3])
s = f"The result of {temp[1]} {temp[2]} {temp[3]} is {div}.\n"
task1b_output.write(s)
task1b_input.close()
task1b_output.close()