-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionalCalc.py
More file actions
54 lines (42 loc) · 1.17 KB
/
Copy pathconditionalCalc.py
File metadata and controls
54 lines (42 loc) · 1.17 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
# A calculator that demonstrates conditional logic and simple functions
request = input("What type of operation would you like to do +, -, / or * ?")
Num1 = float(input("Please enter your first number:"))
Num2 = float(input("Please enter your second number:"))
plus = False
minus = False
divide = False
multiply = False
operator = False
def Add(Num1, Num2):
sum = Num1 + Num2
return sum
def Sub(Num1, Num2):
sum = Num1 - Num2
return sum
def Divide(Num1, Num2):
sum = Num1 / Num2
return sum
def Multiply(Num1, Num2):
sum = Num1 * Num2
return sum
if request == "+":
plus = True
answer = Add(Num1, Num2)
print(Num1, "+", Num2, "is equal to ", answer)
if request == "-":
answer = Sub(Num1, Num2)
minus = True
print(Num1, "-", Num2, "is equal to ", answer)
if request == "/":
answer = Divide(Num1, Num2)
divide = True
print(Num1, "/", Num2, "is equal to ", answer)
if request == "*":
answer = Multiply(Num1, Num2)
print(Num1, "*", Num2, "is equal to ", answer)
multiply = True
if plus or minus or divide or multiply:
operator = True
print("\n...Calculation complete...")
else:
operator = False