11"""
2- Class that handles the input_key and calculations
2+ CircuitPython library to handle the input and calculations
3+
4+ * Author(s): Melissa LeBlanc-Williams
35"""
6+
7+ # pylint: disable=eval-used
48class Calculator :
59 def __init__ (self , calc_display , clear_button , label_offset ):
610 self ._calc_display = calc_display
@@ -10,21 +14,22 @@ def __init__(self, calc_display, clear_button, label_offset):
1014 self ._operator = None
1115 self ._equal_pressed = False
1216 self ._operand = None
13- self .all_clear ()
17+ self ._all_clear ()
1418
1519 def calculate (self , number_one , operator , number_two ):
20+
1621 result = eval (number_one + operator + number_two )
1722 if int (result ) == result :
1823 result = int (result )
1924 return str (result )
2025
21- def all_clear (self ):
26+ def _all_clear (self ):
2227 self ._accumulator = "0"
2328 self ._operator = None
2429 self ._equal_pressed = False
25- self .clear_entry ()
30+ self ._clear_entry ()
2631
27- def clear_entry (self ):
32+ def _clear_entry (self ):
2833 self ._operand = None
2934 self ._set_button_ce (False )
3035 self ._set_text ("0" )
@@ -78,7 +83,7 @@ def _handle_operator(self, input_key):
7883 self ._accumulator = self ._get_text ()
7984 self ._equal_pressed = False
8085
81- def _handle_equal (self , input_key ):
86+ def _handle_equal (self ):
8287 if self ._operator is not None :
8388 if self ._operand is None :
8489 self ._operand = self ._get_text ()
@@ -89,9 +94,9 @@ def _handle_equal(self, input_key):
8994 def add_input (self , input_key ):
9095 try :
9196 if input_key == "AC" :
92- self .all_clear ()
97+ self ._all_clear ()
9398 elif input_key == "CE" :
94- self .clear_entry ()
99+ self ._clear_entry ()
95100 elif self ._operator is None and input_key == "0" :
96101 pass
97102 elif len (input_key ) == 1 and 48 <= ord (input_key ) <= 57 :
@@ -108,7 +113,7 @@ def add_input(self, input_key):
108113 elif input_key == "%" :
109114 self ._set_text (self .calculate (self ._get_text (), "/" , "100" ))
110115 elif input_key == "=" :
111- self ._handle_equal (input_key )
116+ self ._handle_equal ()
112117 except (ZeroDivisionError , RuntimeError ):
113- self .all_clear ()
118+ self ._all_clear ()
114119 self ._set_text ("Error" )
0 commit comments