mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Merge pull request #360 from Sankari-K/main
Added generator for percentage error calculation
This commit is contained in:
@@ -13,6 +13,7 @@ from .fraction_multiplication import *
|
||||
from .is_prime import *
|
||||
from .multiplication import *
|
||||
from .percentage import *
|
||||
from .percentage_error import *
|
||||
from .power_of_powers import *
|
||||
from .square import *
|
||||
from .square_root import *
|
||||
|
||||
28
mathgenerator/funcs/basic_math/percentage_error.py
Normal file
28
mathgenerator/funcs/basic_math/percentage_error.py
Normal 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"])
|
||||
Reference in New Issue
Block a user