Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d1a6118
built a working add skeleton
DrakeDwornik Oct 30, 2021
8ff48a6
trying to fix git
DrakeDwornik Oct 30, 2021
282fd74
made a state object
DrakeDwornik Oct 30, 2021
1c966b7
object oriented funtions
DrakeDwornik Oct 30, 2021
da0c6b0
add is not a method of state
DrakeDwornik Oct 30, 2021
1f646f9
matched calc and calc2
DrakeDwornik Oct 30, 2021
9d08e21
capitalized the command input
DrakeDwornik Oct 30, 2021
8a66b9a
capitalized the command input
DrakeDwornik Oct 30, 2021
7caf9b8
cleaned up style
DrakeDwornik Oct 30, 2021
f53afaf
CR test 1
Oct 30, 2021
8737e4f
CR test 2
Oct 30, 2021
ff0defa
CR test 3
Oct 30, 2021
d421f31
CR test 4
Oct 30, 2021
8a92d2d
I added all math functions
Oct 31, 2021
14627b4
added docstrings
Oct 31, 2021
3a608be
started adding error handling and tests
DrakeDwornik Oct 31, 2021
fe386bb
added more tests, and error handling
DrakeDwornik Oct 31, 2021
a1ce2f4
uploaded to memory branch
Oct 31, 2021
116c3c9
Merge branch 'master' into creasen
Oct 31, 2021
aab8ef6
Merge pull request #1 from DrakeDwornik/creasen
Oct 31, 2021
9a244ff
testing branch
Oct 31, 2021
496706d
Merge pull request #2 from DrakeDwornik/croethel
croethel Oct 31, 2021
a16e9b9
Merge branch 'master' into drake2
Oct 31, 2021
7bf2912
Merge pull request #3 from DrakeDwornik/drake2
croethel Oct 31, 2021
4d6532f
trying to test
Oct 31, 2021
8824962
test
Oct 31, 2021
c519522
added state
DrakeDwornik Oct 31, 2021
0a9a68a
Merge pull request #5 from DrakeDwornik/christine2
croethel Oct 31, 2021
7d394c2
Merge pull request #6 from DrakeDwornik/drake2
croethel Oct 31, 2021
1ceaa21
added degrees and radians
Oct 31, 2021
6847e65
made small formatting changes
Oct 31, 2021
4bfa7f9
made more changes
Oct 31, 2021
b6930ef
Merge pull request #7 from DrakeDwornik/christine2
Oct 31, 2021
e21a750
started using state for result
DrakeDwornik Oct 31, 2021
193af68
Merge pull request #8 from DrakeDwornik/drake2
Oct 31, 2021
04409ce
converted memstore to state object
DrakeDwornik Oct 31, 2021
2543b66
Merge pull request #10 from DrakeDwornik/drake2
Oct 31, 2021
7000e5f
Create test
Oct 31, 2021
3b9422a
deleted test file
DrakeDwornik Oct 31, 2021
ee12e84
Merge pull request #11 from DrakeDwornik/drake2
Oct 31, 2021
edc7b56
made more changes2
Nov 1, 2021
a7cf9a2
changes with drake
Nov 1, 2021
0f86c72
changes with drake2
Nov 1, 2021
a7d451e
changes with drake3
Nov 1, 2021
0646038
Merge pull request #12 from DrakeDwornik/christine2
Nov 1, 2021
ad9d6f4
pi & eval in main
Nov 1, 2021
206f867
Merge pull request #13 from DrakeDwornik/christine2
Nov 1, 2021
40d2f80
added eval to the calculator class
DrakeDwornik Nov 1, 2021
7ffbae5
Merge pull request #14 from DrakeDwornik/drake3
Nov 1, 2021
6d122f1
git experiment
DrakeDwornik Nov 1, 2021
f43bd3c
Merge pull request #15 from DrakeDwornik/drake3
Nov 1, 2021
9f30e3f
I have made changes
Nov 1, 2021
e072ca7
I have made more changes
Nov 1, 2021
2db5764
Merge pull request #16 from DrakeDwornik/memory
Nov 1, 2021
62bebd1
fixed duplicate inverse functions
Nov 1, 2021
923d406
Merge pull request #17 from DrakeDwornik/memory
Nov 1, 2021
39796f7
fixed math functions & removed extra print statements
Nov 1, 2021
7730e6d
removed redundant print statement
Nov 1, 2021
5f26c7f
Merge pull request #18 from DrakeDwornik/memory
Nov 1, 2021
4d48ba0
Finished adding tests and cleaning failures
DrakeDwornik Nov 1, 2021
e7fd962
Merge pull request #19 from DrakeDwornik/drake3
Nov 1, 2021
afcaf2c
put main loop in __init__
DrakeDwornik Nov 1, 2021
8c552d8
Merge pull request #20 from DrakeDwornik/drake3
Nov 1, 2021
8ea073d
added error removed second loop
DrakeDwornik Nov 1, 2021
51160ce
Merge pull request #21 from DrakeDwornik/drake3
Nov 1, 2021
71b1202
switching through to single loop
DrakeDwornik Nov 1, 2021
883c07b
added more error handling
DrakeDwornik Nov 1, 2021
c24f0b7
Merge pull request #22 from DrakeDwornik/drake3
Nov 1, 2021
57661ae
Merge pull request #23 from DrakeDwornik/staging
Nov 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions buttons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#list of calculator buttons and function definitions
##Core
`state` <- represents the screen

`get current number on display`

`clear the display`

`add`
add(a: float, b:float) -> float

`sub`
sub(a: float, b:float) -> float

`multiply`

`divide`

`squre`

`square_root`

`exponentiate`

`inverse`

`invert_sign`

##scientific
###Display
`switch_display_rotate`
`switch_display_str`
`display_binary`
`display_octal`
`display_decimal`
`display_hex`
###memmory
* store 1 value (for recall)

`m+` (puts display in memory)
`mc` (clears memory)
`mrc` (puts memory on screen)

###trig
`sin`
`cos`
`tan`
`asin` (inverse)
`acos`
`atan`
###switch trig mode
rads and degrees
rads_degrees_swap() -> str
switch and string
25 changes: 25 additions & 0 deletions calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from calculator import State

state = State()

while True:
state.print()
if state.command is None:
print("current command is:", state.command)
state.user_entry = input("please enter a mathematical function or number (or type help): ")
if state.user_entry.isnumeric():
state.user_entry = float(state.user_entry)
if state.command is None:
state.value = state.user_entry
elif state.command == "+":
state.add(state.user_entry)
elif state.command == "-":
state.sub(state.user_entry)
elif state.user_entry.upper() == "HELP":
state.help()
continue
elif state.user_entry.upper() == "EXIT":
break
else:
state.command = state.user_entry.upper()
print("thanks for pushing all my buttons")
267 changes: 261 additions & 6 deletions calculator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,267 @@

import math

class Calculator:

def __init__(self):
pass

def add(self, x, y):
return x + y
self.error = False
self.result = 0
self.degrees = True
self.display_mode = "decimal"
self.stored_number = 0
self.exit = False

def err(self):
self.error = True

def eval_function(self, x: str):
"""
evaluates x to return a result
"""
try:
result = eval(x)
return result
except:
self.err()
return "Err"



def add(self, a, b):
"""
ADDS TWO NUMBERS AND RETURNS RESULT
:param a:
:param b:
:return:
"""
return a + b


def subtract(self, x, y):
"""
SUBTRACTS TWO NUMBERS AND RETURNS RESULT
:param x:
:param y:
:return:
"""
return x - y


def multiply(self, x, y):
"""
MULTIPLIES TWO NUMBERS AND RETURNS RESULT
:param x:
:param y:
:return:
"""
return y * x


def divide(self, x, y):

"""
DIVIDES TWO NUMBERS AND RETURNS RESULT
:param x:
:param y:
:return:
"""
try:
result = x / y
except:
result = "Err"
self.err()
return result

return result


def square(self, base):
"""
SQUARES A NUMBER AND RETURNS RESULT
:param base:
:return:
"""
return base ** 2


def exp(self, x, y):
"""
EXPONENTIATES TWO NUMBERS AND RETURNS RESULT
:param x:
:param y:
:return:
"""
return x ** y


def square_root(self, x):
"""
FINDS THE SQUARE ROOT OF A NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
print(math.sqrt(x))
except:
self.err()
return "Err"
return math.sqrt(x)


def invert(self, x):
"""
INVERSES A NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
result = 1/x
return result
except:
self.err()
return "Err"


def deg_rad_swap(self):
"""
SWAPS BETWEEN RADIANS AND DEGREES
:return:
"""
self.degrees = not self.degrees

def sin(self, x):
"""
FINDS SINE OF NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
if self.degrees:
x = math.radians(x)
return math.sin(x)
except:
return "Err"

def cosine(self, x):
"""
FINDS COSINE OF NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
if self.degrees:
x = math.radians(x)
x = math.cos(x)
return x
except:
return "Err"

def tangent(self, x):
"""
FINDS TANGENT OF NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
if self.degrees:
x = math.radians(x)
x = math.tan(x)
return x
except:
return "Err"

def inverse_sine(self, x):
"""
FINDS INVERSE SINE OF NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
if self.degrees:
x = math.degrees(math.asin(x))
else:
x = math.asin(x)
return x
except:
return "Err"

def inverse_cosine(self, x):
"""
FINDS INVERSE COSINE OF NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
if self.degrees:
x = math.degrees(math.acos(x))
else:
x = math.acos(x)
return x
except:
return "Err"

def inverse_tangent(self, x):
"""
FINDS INVERSE TANGENT OF NUMBER AND RETURNS RESULT
:param x:
:return:
"""
try:
if self.degrees:
x = math.degrees(math.atan(x))
else:
x = math.atan(x)
return x
except:
return "Err"

##SECONDARY FORMULAS

def add2(self, x):
"""
ADDS A NUMBER WITH THE SAME NUMBER
:param x:
:return:
"""
print(self.result + x)
return self.result + x


def subtract2(self, x):
"""
SUBTRACTS A NUMBER WITH THE SAME NUMBER
:param x:
:return:
"""
print(self.result - x)
return self.result - x


def multiply2(self, x):
"""
MULTIPLIES A NUMBER WITH THE SAME NUMBER
:param x:
:return:
"""
# print( self.result * x)
return self.result * x


def divide2(self, x):
"""
DIVIDES A NUMBER WITH THE SAME NUMBER
:param x:
:return:
"""

print(self.result / x)
return self.result / x

def clr(self,ce):
test = ce.upper()
if test == "CE":
self.error = False
self.result = 0

def sub(self, x, y):
return 0

# add lots more methods to this calculator class.
Empty file added empty_file
Empty file.
34 changes: 0 additions & 34 deletions main-app.py

This file was deleted.

Loading