-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
67 lines (66 loc) · 1.65 KB
/
calculator.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
""""
Variáveis:
a
b
r
op1
op2
op3
"""
print ("\n")
print ("Bem-vindo(a) à Calculadora do Raphael"); print ("\n")
op3 = "="
op1 = ""
while op1 != "a":
# 1ª parte: a + b = r :
a = input ("Número: ")
while op1 != "a":
# 3ª parte - loop:
if op3 != "=":
b = input("Número: ")
else:
op1 = input("Operação: ")
b = input("Número: ")
if op1 == "+":
r = float(a) + float(b)
elif op1 == "-":
r = float(a) - float(b)
elif op1 == "*":
r = float(a) * float(b)
elif op1 == "/":
r = float(a) / float(b)
elif op1 == "//":
r = float(a) // float(b)
elif op1 == "%":
r = float(a) % float(b)
elif op1 == "^" or op1 == "**":
r = float(a) ** float(b)
elif op1 == "=":
print (r)
op2 = input ("Operação: ")
if op2 == "=":
print ("\n")
print (r)
print ("\n")
break
# 2ª parte: r + b = a :
b = input ("Número: ")
if op2 == "+":
a = float(r) + float(b)
elif op2 == "-":
a = float(r) - float(b)
elif op2 == "*":
a = float(r) * float(b)
elif op2 == "/":
a = float(r) / float(b)
elif op2 == "//":
a = float(r) // float(b)
elif op2 == "%":
a = float(r) % float(b)
elif op2 == "^" or op3 == "**":
a = float(r) ** float(b)
op3 = input ("Operação: ")
if op3 == "=":
print ("\n")
print (a)
break