Skip to main content

pymeg

Table of Contents

General Info

Python mathematical expression generator

Class Overview

  • AbstractExpStruct

Abstract class of ExpStruct.

This class has four constants.

AbstractExpStruct.PLUS = 0

AbstractExpStruct.MINUS = 1

AbstractExpStruct.MULTIPLY = 2

AbstractExpStruct.DIVIDE = 3
  • ExpStruct

Class which can store the rules of expression. inherits the AbstractExpStruct.

ExpStruct has methods like below.

set_op(lst) # set the operators to be used to expression to generate as AbstractExpStruct's constant. 

# For example, if you want to use only plus and minus then write like this

# expStruct.set_op([AbstractExpStruct.PLUS, AbstractExpStruct.Minus])



get_op() -> self.__op_lst # get the operators to be used as list of AbstractExpStruct's constant.



set_oper_cnt(cnt) # set the number of operands of expression to be generated.



set_range(min_, max_, types: list) # set min, max number to use of types(plus, minus ...).
  • ExpGenerator

Class which generate the randomized expression with given ExpStruct instance

Using get_problem static method to generate the expression. Argument is ExpStruct.

Result is string-typed mathematical expression.


problem = ExpStruct()

ExpGenerator.get_problem(problem)

Setup

python -m pip install pymeg

Example

Code Sample

from pymeg.expGenerator import ExpGenerator

from pymeg.expStruct import ExpStruct



problem = ExpStruct()

problem.set_oper_cnt(4)

problem.set_range(20, 100, [ExpStruct.PLUS, ExpStruct.MINUS])

problem.set_range(2, 10, [ExpStruct.MULTIPLY])

problem.set_range(2, 4, [ExpStruct.DIVIDE])

print(ExpGenerator.get_problem(problem))

print(ExpGenerator.get_problem(problem))

print(ExpGenerator.get_problem(problem))

ext = ExpGenerator.get_problem(problem)

print(ext)

print(eval(ext))

Result

Note: Problem will be generated randomly depending on operand count set by user.

54+25-54*9

6*6-31/3

2/4*8/3

9*3*6/2

81.0

Metadata

Release files for pymeg 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymeg 0.0.12
File Size Uploaded
pymeg-0.0.12.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymeg 0.0.12
File Interpreter ABI Platform
pymeg-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / pymeg-0.0.12.tar.gz

Download URL pymeg-0.0.12.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ada322e531365520a85c965a53520c915123f79d7790dc4db5638a433934c911
BLAKE2b-256 checksum
How to use checksums
d63c76aa36e13de37f76e33c672fb00ad1bc6283f6ea68c9bc4446e44fdfa682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.7.6

Release files / pymeg-0.0.12-py3-none-any.whl

Download URL pymeg-0.0.12-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81a05ca54fb2c911f48f81fe1f75e0fe7458848df22e1eff8cdfb86d56c075cb
BLAKE2b-256 checksum
How to use checksums
9f8c4cf4440c60c2fd7c93009f785a5cc48ed3407cc530ca6ea11f8558620436
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page