-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalc.py
More file actions
53 lines (53 loc) · 1001 Bytes
/
calc.py
File metadata and controls
53 lines (53 loc) · 1001 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
i = 0
total = 0
lastoperator = ''
bfirst = 1
mystr = input()
for str in mystr:
if str == '=' and bfirst == 0:
if lastoperator == '+':
total += int(str1)
elif lastoperator == '-':
total -= int(str1)
elif lastoperator == '*':
total *= int(str1)
elif lastoperator == '/':
total /= int(str1)
else:
pass
i += 1
elif str == '+':
if bfirst == 0:
total += int(str1)
else:
bfirst = 0
lastoperator = str
elif str == '-':
if bfirst == 0:
total -= int(str1)
else:
bfirst = 0
lastoperator = str
elif str == '*':
if bfirst == 0:
total *= int(str1)
else:
bfirst = 0
lastoperator = str
elif str == '/':
if bfirst == 0:
total /= int(str1)
else:
bfirst = 0
lastoperator = str
elif str == ' ':
pass
else:
if bfirst == 1:
total = int(str)
bfirst = 2
elif bfirst == 0:
str1 = str
else:
pass
print(total)