-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybettercalculator.py
159 lines (128 loc) · 6.11 KB
/
mybettercalculator.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
import math
def sin_function(a):
radian_a = (3.141592653589793 / 180) * a
unrounded_answer = radian_a
for turn in range(1, 9):
turn_multiplier = turn * 2 + 1
unrounded_answer = unrounded_answer + math.pow(radian_a, turn_multiplier) / math.factorial(turn_multiplier) * math.pow(-1, turn)
answer = round(unrounded_answer, 6)
return answer
def cos_function(a):
radian_a = (3.141592653589793 / 180) * a
unrounded_answer = 1
for turn in range(1, 9):
turn_multiplier = turn * 2
unrounded_answer = unrounded_answer + math.pow(radian_a, turn_multiplier) / math.factorial(turn_multiplier) * math.pow(-1, turn)
answer = round(unrounded_answer, 6)
return answer
def tan_function(a):
answer = sin_function(a) / cos_function(a)
return answer
def cot_function(a):
answer = cos_function(a) / sin_function(a)
return answer
print ("Hello, welcome to my Calculator")
question_1 = input ("Input either of these sum, difference, squareeq, multiply, division, root, power, percentage, squareofthesum, squareofthedifference, differenceofsquares, sin, cos and there are more coming soon: ")
if (question_1 == "sum"):
a = int (input ("Input a, for the a + b formula: "))
b = int (input ("Input b, for the a + b formula: "))
print (a, "+", b, "=", a + b)
elif (question_1 == "difference"):
a = int (input ("Input a, for the a - b formula: "))
b = int (input ("Input b, for the a - b formula: "))
print ("a + b =", a, "-", b, "=", a - b)
elif (question_1 == "multiply"):
a = int (input ("Input a, for the a * b formula: "))
b = int (input ("Input b, for the a * b formula: "))
print ("a - b =", a, "*", b, "=", a * b)
elif (question_1 == "division"):
a = int (input ("Input a, for the a / b formula: "))
b = int (input ("Input b, for the a / b formula: "))
print ("a / b =", a, "/", b, "=", a / b)
elif (question_1 == "power"):
a = int (input ("Input a, for the a ^ b formula: "))
b = int (input ("Input b (power), for the a ^ b formula: "))
print ("a ^ b =", a, "^", b, "=", math.pow (a, b))
elif (question_1 == "root"):
a = int (input ("Input a, for the a ^ 1 / b formula: "))
b = int (input ("Input b, for the a ^ 1 / b formula: "))
print("a ^ 1 / b =", a, "^ 1 /", b, "=", math.pow(a, 1 / b))
elif (question_1 == "factorial"):
a = int (input ("Input a(for the a! or a factorial formula): "))
factorialalex = 1
if (a == 0):
print("0! = 1")
else:
for i in range(1, a + 1) :
factorialalex = factorialalex * i
print(a, "! = ", factorialalex)
elif (question_1 == "percentage"):
a = int (input ("Input a(for the a %% b formula): "))
b = int (input ("Input b(for the a %% b formula): "))
percentage = a * b / 100
print("a %% b =", "%s%%"% percentage)
elif (question_1 == "squareofthesum"):
a = int (input ("Input a(for the (a + b)^2 formula): "))
b = int (input ("Input b(for the (a + b)^2 formula): "))
print("(a + b)^2 = a^2 + 2 * a * b + b^2 =", a * a + 2 * a * b + b * b)
elif (question_1 == "squareofthedifference"):
a = int (input ("Input a(for the (a - b)^2 formula): "))
b = int (input ("Input b(for the (a - b)^2 formula): "))
print("(a - b)^2 = a^2 - 2 * a * b + b^2 =", a * a - 2 * a * b + b * b)
elif (question_1 == "differenceofsquares"):
a = int (input ("Input a(for the a^2 - b^2 formula): "))
b = int (input ("Input b(for the a^2 - b^2 formula): "))
print("a^2 - b^2 = (a - b) * (a + b) =", (a - b) * (a + b))
elif (question_1 == "sin"):
a = int (input ("Input the angle in degrees for the sin(angle) formula: "))
print("sin(", a, ") = ", sin_function(a))
elif (question_1 == "cos"):
a = int (input ("Input the angle in degrees for the cos(angle) formula: "))
radian_a = (3.141592653589793 / 180) * a
print("cos(", a, ") = ", cos_function(a))
elif (question_1 == "tan"):
a = int (input ("Input the angle in degrees for the tan(angle) formula: "))
if (a == 90):
print("tan(", a, ") is not defined.")
else:
print("tan(", a, ") = ", cos_function(a))
elif (question_1 == "cot"):
a = int (input ("Input the angle in degrees for the cot(angle) formula: "))
if (a == 0):
print("cot(", a, ") is not defined.")
else:
print("cot(", a, ") = ", cos_function(a))
elif (question_1 == "squareeq"):
print ('Input a, for the ax2 + bx + c formula: ')
a = int (input ())
print ('Input b, for the ax2 + bx + c formula: ')
b = int (input ())
print ('Input c, for the ax2 + bx + c formula: ')
c = int (input ())
b2 = b ** 2
ac = 4 * a * c
#x1 = (- b - math.sqrt ((b2 - ac))) / (2 * a)
#x2 = (- b + math.sqrt ((b2 - ac))) / (2 * a)
#print(a, 'x2' + ' + ', b, 'x' + ' + ', c, + ' = ' + '0')
if (b2 - ac < 0):
#x1 = (- b - ( - math.sqrt ((- b2 + ac)))) / (2 * a)
#x2 = (- b + ( - math.sqrt ((- b2 + ac)))) / (2 * a)
#print ('D = b * b - 4ac =', b2 - ac, "sqrt (", b2 - ac, ") =", - math.sqrt (- b2 + ac))
#print ('x1 = (- b - sqrt (D)) / 2a =', x1, "+ i")
#print ('x2 = (- b + sqrt (D)) / 2a =', x2, "+ i")
print("X can't be any number from the Real Numbers.")
#make irreal number support
elif (b2 - ac > 0):
x1 = (- b - math.sqrt ((b2 - ac))) / (2 * a)
x2 = (- b + math.sqrt ((b2 - ac))) / (2 * a)
print ('D = b * b - 4ac =', b2 - ac, "sqrt (", b2 - ac, ") =", math.sqrt (b2 - ac))
print ('x1 = (- b - sqrt (D)) / 2a =', x1)
print ('x2 = (- b + sqrt (D)) / 2a =', x2)
else:
x1 = (- b - math.sqrt ((b2 - ac))) / (2 * a)
print ('D = b * b + 4ac =', b2 - ac, "sqrt (", b2 - ac, ") =", math.sqrt (b2 - ac))
print ("x = (- b - sqrt (0)) / 2a =", x1)
elif (question_1 == "help"):
print("Welcome to the help menu of this program.\n\nHere are some of the options you should consider using:\nsum - Calculating the sum of two numbers.\ndifference - Calculating the difference of the two numbers.\nmultiply - Calculating the product of the two numbers.\ndivision - Calculating the quotient of the two inputed numbers.")
else:
print ("Try again.")