mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Merge pull request #367 from Sankari-K/main
Added generator for percent difference
This commit is contained in:
@@ -14,6 +14,7 @@ from .greatest_common_divisor import *
|
||||
from .is_prime import *
|
||||
from .multiplication import *
|
||||
from .percentage import *
|
||||
from .percentage_difference import *
|
||||
from .percentage_error import *
|
||||
from .power_of_powers import *
|
||||
from .square import *
|
||||
|
||||
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"])
|
||||
@@ -19,10 +19,10 @@ from .is_leap_year import *
|
||||
from .lcm import *
|
||||
from .minutes_to_hours import *
|
||||
from .prime_factors import *
|
||||
from .product_of_scientific_notations import *
|
||||
from .profit_loss_percent import *
|
||||
from .quotient_of_power_same_base import *
|
||||
from .quotient_of_power_same_power import *
|
||||
from .set_operation import *
|
||||
from .signum_function import *
|
||||
from .surds_comparison import *
|
||||
from .product_of_scientific_notations import *
|
||||
|
||||
Reference in New Issue
Block a user