def apply_operation(left_operand, right_operand, operator_input): # Check if input arguments are of valid int or float type if type(convert(left_operand)) == str or type(convert(right_operand)) == str: # convert function from Q2 print "Input data not integer or float type" return # Continue for valid input, using convert function from Q2 for appropriate conversion operator_table = { '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.div} if operator_input not in operator_table: print "Invalid operator, try again" return else: # Check for division by zero error try: return operator_table[operator_input](left_operand, right_operand) except: print "Division by zero is an invalid operation" return
def customTester(): print(" ") print("Custom tester") s = str(raw_input("Enter a string to convert ('q' to quit): ")) while s != 'q': print(s) print(type(convert(s))) s = str( raw_input( "Enter string for conversion tester ('q' to quit program): "))
def min_new(*args): # Check if input arguments are of valid int or float type check = 0 for input in args: if type(convert(input)) == str: # convert function from Q2 check += 1 if check != 0: print "Input data not integer or float type" return None # Continue for valid input, using convert function from Q2 for appropriate conversion min_current = convert(args[0]) for input in args: if min_current > convert(input): min_current = convert(input) return min_current
def unitTests(): a = "1" b = "1.0" c = "asd" d = "A1B2C3.3;;'" e = "{\{{{PP{O}}" f = "12777777*" g = "+asssssdf" h = "123666.6345" i = "-123" j = "0" print(""" Some unit tests are: a = "1" b = "1.0" c = "asd" d = "A1B2C3.3;;'" e = "{\{{{PP{O}}" f = "1#2777777*" g = "+asssssdf" h = "123666.6345" i = "-123" j = "0" """) print("Result from convert function:") print(type(convert(a))) print(type(convert(b))) print(type(convert(c))) print(type(convert(d))) print(type(convert(e))) print(type(convert(f))) print(type(convert(g))) print(type(convert(h))) print(type(convert(i))) print(type(convert(j)))
# Test driver for Q4 from Q2 import convert import Q4 while 1: num1 = convert(str(raw_input("Enter 1st number ('q' to quit): "))) if num1 == 'q': break num2 = convert(str(raw_input("Enter 2st number ('q' to quit): "))) if num2 == 'q': break num3 = convert(str(raw_input("Enter 3st number ('q' to quit): "))) if num3 == 'q': break print("Inputs: " + str(num1) + ", " + str(num2) + ", " + str(num3)) print("The minimum value is " + str(Q4.findMinimum(num1, num2, num3)))
# Test driver for Q5 from Q2 import convert import Q5 while 1: left_operand = convert(str( raw_input("Enter left_operand ('q' to quit): "))) if left_operand == 'q': break right_operand = convert( str(raw_input("Enter right_operand ('q' to quit): "))) if right_operand == 'q': break operator = convert(str(raw_input("Enter operator ('q' to quit): "))) if operator == 'q': break print("Inputs: " + str(left_operand) + ", " + str(right_operand) + ", " + str(operator)) print("Result is: " + str(Q5.apply_operation(left_operand, right_operand, operator)))