Added generator for percentage difference

This commit is contained in:
Sankari Karthik
2021-10-11 08:54:35 +05:30
parent 5a534e242b
commit b73fe7688b

View 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"])