diff --git a/generator.py b/generator.py index c55db36..0a7545a 100644 --- a/generator.py +++ b/generator.py @@ -14,9 +14,9 @@ num_of_ifs = len(signs)*(max_num-min_num)**2 print("""# my_first_calculator.py by AceLewis # TODO: Make it work for all floating point numbers too -if 3/2 == 1: # Because Python 2 does not know maths - input = raw_input # Python 2 compatibility - +if 3/2 == 1: # Because Python 2 does not know maths + input = raw_input # Python 2 compatibility + print('Welcome to this calculator!') print('It can add, subtract, multiply and divide whole numbers from {} to {}') num1 = int(input('Please choose your first number: ')) @@ -33,14 +33,15 @@ for sign in signs: equals = eval(equation) except ZeroDivisionError: equals = 'Inf' - except decimal.InvalidOperation: - equals = 'Inf' + except decimal.InvalidOperation as error: + if error == decimal.DivisionByZero: + equals = 'Inf' + else: + equals = 'Undefined' # No elif's used to be true to the story and also because # Python will throw a recursion error when too many are used - print("if num1 == {} and sign == '{}' and num2 == {}:".format(num1, sign, num2), - file=python_file) - print(' print("{}{}{} = {}")'.format(num1, sign, num2, equals), -file=python_file) + print("if num1 == {} and sign == '{}' and num2 == {}:".format(num1, sign, num2), file=python_file) + print(' print("{}{}{} = {}")'.format(num1, sign, num2, equals), file=python_file) print('', file=python_file) print('print("Thanks for using this calculator, goodbye :)")', file=python_file) diff --git a/my_first_calculator.py b/my_first_calculator.py index 16dd2bc..bf7c560 100644 --- a/my_first_calculator.py +++ b/my_first_calculator.py @@ -1,9 +1,9 @@ # my_first_calculator.py by AceLewis # TODO: Make it work for all floating point numbers too -if 3/2 == 1: # Because Python 2 does not know maths - input = raw_input # Python 2 compatibility - +if 3/2 == 1: # Because Python 2 does not know maths + input = raw_input # Python 2 compatibility + print('Welcome to this calculator!') print('It can add, subtract, multiply and divide whole numbers from 0 to 50') num1 = int(input('Please choose your first number: ')) @@ -10415,7 +10415,7 @@ if num1 == 50 and sign == '-' and num2 == 49: if num1 == 50 and sign == '-' and num2 == 50: print("50-50 = 0") if num1 == 0 and sign == '/' and num2 == 0: - print("0/0 = Inf") + print("0/0 = Undefined") if num1 == 0 and sign == '/' and num2 == 1: print("0/1 = 0") if num1 == 0 and sign == '/' and num2 == 2: