From 36777d685f89cb1b32ecc1ed07a573181b396204 Mon Sep 17 00:00:00 2001 From: Hussain Omer <67332652+hussaino03@users.noreply.github.com> Date: Wed, 17 Aug 2022 22:51:36 -0400 Subject: [PATCH] added iscomposite (#384) * added iscomposite (Math function) * Update README.md * Update and rename iscomposite.py to is_composite.py Co-authored-by: Luke Weiler --- README.md | 1 + .../funcs/basic_math/is_composite.py | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 mathgenerator/funcs/basic_math/is_composite.py diff --git a/README.md b/README.md index db8212d..dec3d5a 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ This creates the pdf `ws.pdf` in your current directory | 118 | [Percentage difference](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/percentage_difference.py) | What is the percentage difference between 53 and 90? | 51.75% | percentage_difference | `maxValue=200` `minValue=0` | | 119 | [Percentage error](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/percentage_error.py) | Find the percentage error when observed value equals 33 and exact value equals 61. | 45.9% | percentage_error | `maxValue=100` `minValue=-100` | | 120 | [Greatest Common Divisor of N Numbers](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/greatest_common_divisor.py) | GCD(21465961,176654083)= | 1 | greatest_common_divisor | `numbersCount=2` `maximalNumberLimit=10**9` | +| 124 | [Is Composite](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/is_composite.py) | Is 8 composite? | Yes | is_composite | `maxNum=250`| ## calculus | Id | Skill | Example problem | Example Solution | Function Name | Kwargs | |------|-------|-----------------|------------------|---------------|--------| diff --git a/mathgenerator/funcs/basic_math/is_composite.py b/mathgenerator/funcs/basic_math/is_composite.py new file mode 100644 index 0000000..d7c60d8 --- /dev/null +++ b/mathgenerator/funcs/basic_math/is_composite.py @@ -0,0 +1,25 @@ +from .__init__ import * + + +def gen_func(maxNum=250, format='string'): + a = random.randint(2, maxNum) + + problem = f"Is {a} composite?" + if a == 0 or a == 1: + solution = "No" + return (problem, solution) + for i in range(2, a): + if a % i == 0: + solution = "Yes" + return (problem, solution) + solution = "No" + + if format == 'string': + return problem, solution + elif format == 'latex': + return "Latex unavailable" + else: + return a, solution + + +is_composite = Generator('Is Composite', 124, gen_func, ["maxNum=250"])