Fixed decimal precision

This commit is contained in:
JuanPotato 2016-05-08 19:26:00 -04:00
parent ce012e5782
commit e4a26bb272
2 changed files with 1961 additions and 1956 deletions

View File

@ -1,3 +1,5 @@
from decimal import Decimal as d
import decimal
# Generator used to create my_first_calculator
# Open a file that we can write to
@ -26,19 +28,22 @@ num2 = int(input('Please choose your second number: '))
for sign in signs:
for num1 in nums:
for num2 in nums:
equation = "{}{}{}".format(num1, sign, num2)
equation = "d({}){}d({})".format(num1, sign, num2)
try:
equals = eval(equation)
except ZeroDivisionError:
equals = 'Inf'
except decimal.InvalidOperation:
equals = 'Inf'
# 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(equation, equals), 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)
# Close the file we have written to
python_file.close()
python_file.close()

File diff suppressed because it is too large Load Diff