-
Notifications
You must be signed in to change notification settings - Fork 1
/
ezmath.py
98 lines (74 loc) · 2.36 KB
/
ezmath.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
# import all math classes, this is a calculator after all
from math import *
# REPL for interactive calculator
from code import InteractiveConsole
# short helper functions to simplify typing on the REPL
def deg(x):
''' short for degrees()'''
return degrees(x)
def rad(x):
'''short for radians()'''
return radians(x)
# sin, cos and tan in degrees
# this is because the python.math module works in radians EXCLUSIVELY
# add degree mode pls
def dsin(x):
'''sin(), but degrees (input and output)'''
return sin(rad(x))
def dcos(x):
'''cos(), but degrees (input and output)'''
return cos(rad(x))
def dtan(x):
'''tan(), but degrees (input and output)'''
return tan(rad(x))
# same as above, just for arc/inverted functions
def dasin(x):
'''asin(), but degrees (input and output)'''
return deg(asin(x))
def dacos(x):
'''acos(), but degrees (input and output)'''
return deg(acos(x))
def datan(x):
'''atan(), but degrees (input and output)'''
return deg(atan(x))
# simple 2d shapes classes
class shape:
'''Does nothing, mainly just here for structure and making inheritence look nice'''
pass
class circle(shape):
'''
Circle class to simplify working with circles.
Params: radius
'''
def __init__(self, radius):
self.radius = radius
self.diameter = radius * 2
def area(self):
return pi * (self.radius ** 2)
class rectangle(shape):
'''
Rectangle class to simplify working with rectangles.
Params: length and width
'''
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return length * width
class square(rectangle):
'''
Square class to simplify working with square.
Params: length
'''
def __init__(self, length):
super().__init__(length, length)
def cone_volume(radius, height):
return (1/3) * pi * (radius**2) * height
def cylinder_volume(radius, height):
return pi * (radius**2) * height
if __name__ == '__main__':
scope_vars = globals()
# these replacements to match what the default python REPL does
scope_vars[__name__] = '__console__'
scope_vars[__doc__] = None
InteractiveConsole(locals=scope_vars).interact('helo welcum to calculator with added stuff :)')