mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Added generator for percentage difference
This commit is contained in:
24
mathgenerator/funcs/basic_math/percentage_difference.py
Normal file
24
mathgenerator/funcs/basic_math/percentage_difference.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
|
def gen_func(maxValue=200, minValue=0, format='string'):
|
||||||
|
value_a = random.randint(minValue, maxValue)
|
||||||
|
value_b = random.randint(minValue, maxValue)
|
||||||
|
|
||||||
|
diff = 2 * (abs(value_a - value_b) / abs(value_a + value_b)) * 100
|
||||||
|
diff = round(diff, 2)
|
||||||
|
|
||||||
|
if format == 'string':
|
||||||
|
problem = f"What is the percentage difference between {value_a} and {value_b}?"
|
||||||
|
solution = str(diff) + "%"
|
||||||
|
return problem, solution
|
||||||
|
|
||||||
|
elif format == 'latex':
|
||||||
|
return 'Latex unavailable'
|
||||||
|
|
||||||
|
else:
|
||||||
|
return value_a, value_b, diff
|
||||||
|
|
||||||
|
|
||||||
|
percentage_difference = Generator("Percentage difference", <id>, gen_func,
|
||||||
|
["maxValue=200", "minValue=0"])
|
||||||
Reference in New Issue
Block a user