def get_sin(): # Computes the sin of the required value basic_1() if (flag == 0 and len(basechar_str) != 0 and len(num_str) != 0): obj_Scientific = class_def.Calculater(basechar_list) num1 = obj_Scientific.convert_to_decimal(num_list) ans_int_val = math.sin(math.radians(num1)) basic_2(ans_int_val, obj_Scientific) tkMessageBox.showinfo("Answer", "sin(" + num_str + ") = " + ans_str) prompt()
def get_multiply(): # Function for multiplication operation basic_2() if (flag == 0 and (len(basechar_list_entry_1) != 0 and len(entry_list_number_1) != 0 and len(entry_list_number_2) != 0)): obj_Calculate = class_def.Calculater(basechar_list_entry_1) num1 = obj_Calculate.convert_to_decimal(entry_list_number_1) num2 = obj_Calculate.convert_to_decimal(entry_list_number_2) tkMessageBox.showinfo( "Answer", entry_str_number_1 + " * " + entry_str_number_2 + " = " + "".join(obj_Calculate.convert_to_base(num1 * num2)))
def get_arccos(): # Computes the arccos of the required value basic_1() if (flag == 0 and len(basechar_str) != 0 and len(num_str) != 0): obj_Scientific = class_def.Calculater(basechar_list) num1 = obj_Scientific.convert_to_decimal(num_list) if (num1 <= 1 and num1 >= -1): ans_int_val = math.acos(num1) basic_2(ans_int_val, obj_Scientific) tkMessageBox.showinfo("Answer", "acos(" + num_str + ") = " + ans_str) else: tkMessageBox.showinfo("Error", "Not defined") prompt()
def get_remainder(): # Function for modulo division operation basic_2() if (flag == 0 and (len(basechar_list_entry_1) != 0 and len(entry_list_number_1) != 0 and len(entry_list_number_2) != 0)): obj_Calculate = class_def.Calculater(basechar_list_entry_1) num1 = obj_Calculate.convert_to_decimal(entry_list_number_1) num2 = obj_Calculate.convert_to_decimal(entry_list_number_2) try: result = num1 % num2 except ZeroDivisionError: tkMessageBox.showinfo("Error", "Division by zero not possible") else: tkMessageBox.showinfo( "Answer", entry_str_number_1 + " % " + entry_str_number_2 + " = " + "".join(obj_Calculate.convert_to_base(num1 % num2)))
def get_divide(): # Function for division operation basic_2() if (flag == 0 and (len(basechar_list_entry_1) != 0 and len(entry_list_number_1) != 0 and len(entry_list_number_2) != 0)): obj_Calculate = class_def.Calculater(basechar_list_entry_1) num1 = obj_Calculate.convert_to_decimal(entry_list_number_1) num2 = obj_Calculate.convert_to_decimal(entry_list_number_2) try: # Implementation of exception handling result = num1 / num2 except ZeroDivisionError: # ZeroDivisionError is an inbuilt error tkMessageBox.showinfo("Error", "Division by zero not possible") else: tkMessageBox.showinfo( "Answer", entry_str_number_1 + " / " + entry_str_number_2 + " = " + "".join(obj_Calculate.convert_to_base(num1 / num2)))
def get_minus(): # Function for subtraction operation basic_2() if (flag == 0 and (len(basechar_list_entry_1) != 0 and len(entry_list_number_1) != 0 and len(entry_list_number_2) != 0)): obj_Calculate = class_def.Calculater(basechar_list_entry_1) num1 = obj_Calculate.convert_to_decimal(entry_list_number_1) num2 = obj_Calculate.convert_to_decimal(entry_list_number_2) if (num1 >= num2): tkMessageBox.showinfo( "Answer", entry_str_number_1 + " - " + entry_str_number_2 + " = " + "".join(obj_Calculate.convert_to_base(num1 - num2))) else: tkMessageBox.showinfo( "Answer", entry_str_number_1 + " - " + entry_str_number_2 + " = " + "<negative>" + "".join(obj_Calculate.convert_to_base(num2 - num1)))
def get_tan(): # Computes the tan of the required value basic_1() if (flag == 0 and len(basechar_str) != 0 and len(num_str) != 0): obj_Scientific = class_def.Calculater(basechar_list) num1 = obj_Scientific.convert_to_decimal(num_list) tmp = num1 x = tmp / 90 if (((num1 % 90) == 0) and (x % 2 == 1)): tkMessageBox.showinfo("Error", "Not Defined") elif ( (num1 % 90 == 0) and (x % 2 == 0) ): # Math library returns a very large negative number (modulus of the value is very small) ans_int_val = 0 # To prevent that we have decided to treat this as a corner case basic_2(ans_int_val, obj_Scientific) tkMessageBox.showinfo("Answer", "tan(" + num_str + ") = " + ans_str) else: ans_int_val = math.tan(math.radians(num1)) basic_2(ans_int_val, obj_Scientific) tkMessageBox.showinfo("Answer", "tan(" + num_str + ") = " + ans_str) prompt()