-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcalculator-function.py
166 lines (121 loc) · 4.31 KB
/
calculator-function.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
##Pyhton Function Calculator
print("Welcome to calculator")
print("---------------------")
howManyNums = input("Would you like to input 2 or 3 numbers: ")
operatorChoice = ""
num1 = ""
num2 = ""
num3 = ""
#addition
def add(x, y):
return x + y
#subtraction
def subtract(x, y):
return x - y
#multiply
def multiply(x, y):
return x * y
#divide
def divide(x, y):
return x / y
#+ -
def addSub(x, y, z):
return x + y - z
#+ *
def addMulti(x, y, z):
return x + y * z
#+ /
def addDiv(x, y, z):
return x + y / z
#- +
def subAdd(x, y, z):
return x - y + z
#- *
def subMulti(x, y, z):
return x - y * z
#- /
def subDiv(x, y, z):
return x - y / z
#* -
def multiSub(x, y, z):
return x * y - z
#* +
def multiAdd(x, y, z):
return x * y + z
#* /
def multiDiv(x, y, z):
return x * y / z
#/ +
def divAdd(x, y, z):
return x / y + z
#/ -
def divSub(x, y, z):
return x / y - z
#/ *
def divMulti(x, y, z):
return x / y * z
#+ +
def addAdd(x, y, z):
return x + y + z
#- -
def subSub(x, y, z):
return x - y - z
#* *
def multiMulti(x, y, z):
return x * y * z
#/ /
def divDiv(x, y, z):
return x / y / z
print("Thefollowing operators are available on this calculator: +, -, *, /")
print("If you are done using the calculator, type in 'quit' instead of the operator")
print("---------------------")
#
if howManyNums == "3":
while operatorChoice != "quit":
num1 = float(input("Enter your first number: ")) #first number
operatorChoice = input("Operator: ") #operator choice
num2 = float(input("enter your second numebr: ")) #second number
operatorChoice2 = input("second operator: ")
num3 = float(input("enter your third numebr: ")) #second number
if operatorChoice == "+" and operatorChoice2 == "-":
print(num1, "+", num2, "-", num3, "=", addSub(num1, num2, num3))
elif operatorChoice == "+" and operatorChoice2 == "*":
print(num1, "+", num2, "*", num3, "=", addMulti(num1, num2, num3))
elif operatorChoice == "+" and operatorChoice2 == "/":
print(num1, "+", num2, "/", num3, "=", addDiv(num1, num2, num3))
elif operatorChoice == "-" and operatorChoice2 == "+":
print(num1, "-", num2, "+", num3, "=", subAdd(num1, num2, num3))
elif operatorChoice == "-" and operatorChoice2 == "*":
print(num1, "-", num2, "*", num3, "=", subMulti(num1, num2, num3))
elif operatorChoice == "-" and operatorChoice2 == "/":
print(num1, "-", num2, "/", num3, "=", subDiv(num1, num2, num3))
elif operatorChoice == "*" and operatorChoice2 == "+":
print(num1, "*", num2, "+", num3, "=", multiAdd(num1, num2, num3))
elif operatorChoice == "*" and operatorChoice2 == "-":
print(num1, "*", num2, "-", num3, "=", multiSub(num1, num2, num3))
elif operatorChoice == "*" and operatorChoice2 == "/":
print(num1, "*", num2, "/", num3, "=", multiDiv(num1, num2, num3))
elif operatorChoice == "/" and operatorChoice2 == "+":
print(num1, "/", num2, "+", num3, "=", divAdd(num1, num2, num3))
elif operatorChoice == "/" and operatorChoice2 == "-":
print(num1, "/", num2, "-", num3, "=", divSub(num1, num2, num3))
elif operatorChoice == "/" and operatorChoice2 == "*":
print(num1, "/", num2, "*", num3, "=", divMulti(num1, num2, num3))
else:
print("operator not found")
if howManyNums == "2":
while operatorChoice != "quit":
num1 = float(input("Enter your first number: ")) #first number
operatorChoice = input("Enter your operator: ") #operator choice
num2 = float(input("enter your second numebr: ")) #second number
if operatorChoice == "+":
print(num1, "+", num2, "=", add(num1, num2))
elif operatorChoice == "-":
print(num1, "-", num2, "=", subtract(num1, num2))
elif operatorChoice == "*":
print(num1, "*", num2, "=", multiply(num1, num2))
elif operatorChoice == "/":
print(num1, "/", num2, "=", divide(num1, num2))
else:
print("operator not found")
print("Have a good day!")