Software Engineering-Arithmetic py (How did I ever use this stuff in my primary school?) )

Source: Internet
Author: User

Title: Implementing a Command-line program to automatically generate primary arithmetic topics GitHub address: Https://github.com/ILTHEW/wc.git Editor: Huang Hui 3116005178 Assistant: Before building 3116005209 Description:

Natural number: 0, 1, 2, ....

? True score: 1/2, 1/3, 2/3, 1/4, 1 ' 1/2, ....

? Operator: +,?, X,÷.

? Parentheses: (,).

? equals sign: =.

? Separators: spaces (for arithmetic characters and before and after).

? An arithmetic expression:

E = n | E1 + E2 | E1? E2 | E1xe2 | E1÷e2 | (e),
where E, E1 and E2 are expressions, n is the natural number or the true fraction.

? Arithmetic title: E =, where e is an arithmetic expression.

3 Requirements:
    1. Use the-n parameter to control the number of generated problems, such as

Myapp.exe-n 10

10 topics will be generated.

    1. Use the-r parameter to control the range of values in the topic (natural number, true fraction, and true fraction denominator), for example

Myapp.exe-r 10

The arithmetic topic will be generated within 10 (excluding 10). This parameter can be set to 1 or other natural number. This parameter must be given, otherwise the program will error and give help information.

    1. The calculation process in the generated topic cannot produce negative numbers, that is, if there is a shape like E1 in an arithmetic expression? E2 subexpression, then e1≥e2.
    2. If there are sub-expressions like e1÷e2 in the generated topic, the result should be a true fraction.
    3. There are no more than 3 operators in each topic.
    4. The problem of the generation of a program run can not be repeated, that is, any two topics cannot be transformed into the same topic by means of a finite exchange + and an arithmetic expression around X. For example, 23 + 45 = and 45 + 23 = are repetitive topics, 6x8 = and 8x6 = are also repetitive topics. The two topics of 2+1 and 1+2+3 are repetitive, because the + is left-associative, and 1+2+3 is equivalent to (1+2) +3, which is the total (1+2), which is (2+1). However, 1+2+3 and 3+2+1 are two non-repetitive problems, because 1+2+3 is equivalent to (1+2) +3, and 3+2+1 is equivalent to (3+2) +1, and they cannot be changed to the same subject by a finite exchange.
      The generated topic is stored in the Exercises.txt file under the current directory of the executing program, in the following format:

    5. Arithmetic Topic 1
    6. Arithmetic Topic 2
      ......

Where true scores are used in the input and output format, the true score Three-fifths is 3/5, the true fraction Two and three-eighths is 2 ' 3/8.

    1. At the same time, the problem is generated and the answers to all the questions are calculated and stored in the Answers.txt file in the current directory of the executing program, in the following format:

    2. Answer 1
    3. Answer 2

In particular, the operation of the true fraction is shown in the following example: 1/6 + 1/8 = 7/24.

    1. The program should be able to support the generation of 10,000 topics.
    2. The program supports a given topic file and answer file, determines the correct error in the answer and carries out the quantity statistics, the input parameters are as follows:

Myapp.exe-e

The statistical results are output to the file Grade.txt, in the following format:

Correct:5 (1, 3, 5, 7, 9)
Wrong:5 (2, 4, 6, 8, 10)

where ":" After the number 5 indicates the number of correct/wrong questions, in parentheses is the number of the right/wrong topic. For the sake of simplicity, assume that the input topics are numbered in sequence and conform to the specifications.

Features that are not implemented
    1. The program supports a given problem file and answer file, determining the correct error in the answer and counting the numbers
    2. The calculation process in the generated topic cannot produce negative numbers, that is, if there is a shape like E1 in an arithmetic expression? E2 subexpression, then e1≥e2
    3. If there are sub-expressions like e1÷e2 in the generated topic, the result should be a true fraction.
    4. The problem of generating a program run once cannot be repeated, that is, no two topics can be transformed into the same problem by a finite exchange + and an arithmetic expression around X

      Problems encountered

      And I work with the small partner is Python, and I am more inclined to Java, and finally because of my skills are not perfect, the use of Python.
      At first thinking about how to randomly generate operators, how to generate an operator after the answer to the operator, and later on the internet found that the Python function library has this function, as long as the easy to call it. Later did not know how to generate documents, and later on the Internet to check a bit, and found that the function is called. And so the two of them did it slowly.

PSP Table

Performance analysis

The algorithm runs slowly, does not use the data structure to optimize, uses the library function extensively, causes the result to run slowly

Design implementation Process

The first is to realize the arithmetic of integers,

Then consider the arithmetic of the score,

Finally generate the title and answer to two files.

Code description

Test Run General


10,000-way topics





Summary

Two people together to explore a lot faster than a person, a lot of efficiency, sometimes a person can not see the problem, another person could be seen and timely reminders. What do not understand where you can find the Niang. Two people have never had a clue to start, slowly found the direction. This seemingly simple project, for me, is a big challenge, which proves that my level has yet to be improved. Always afraid of this unfamiliar things, do not want to challenge it, and finally only in deadline before the night fight, this feeling is not good. What's more, procrastination kills people.

Software Engineering-Arithmetic py (How did I ever use this stuff in my primary school?) )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.