Merge pull request #360 from Sankari-K/main

Added generator for percentage error calculation
This commit is contained in:
Luke Weiler
2021-10-09 13:39:01 -04:00
committed by GitHub
2 changed files with 29 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ from .fraction_multiplication import *
from .is_prime import * from .is_prime import *
from .multiplication import * from .multiplication import *
from .percentage import * from .percentage import *
from .percentage_error import *
from .power_of_powers import * from .power_of_powers import *
from .square import * from .square import *
from .square_root import * from .square_root import *

View File

@@ -0,0 +1,28 @@
from .__init__ import *
def gen_func(maxValue=100, minValue=-100, format='string'):
observed_value = random.randint(minValue, maxValue)
exact_value = random.randint(minValue, maxValue)
if observed_value * exact_value < 0:
observed_value *= -1
error = (abs(observed_value - exact_value) / abs(exact_value)) * 100
error = round(error, 2)
if format == 'string':
problem = f"Find the percentage error when observed value equals {observed_value} and exact value equals {exact_value}."
solution = str(error) + "%"
return problem, solution
elif format == 'latex':
return 'Latex unavailable'
else:
return observed_value, exact_value, error
percentage_error = Generator(
"Percentage error", <id>, gen_func,
["maxValue=100", "minValue=-100"])