# 1. Operating Specifications and Requirements

Blog class https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19
Work requirements https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/homework/11376
Job target Let's talk about the four operations in the past and implement and be familiar with writing articles in markdown
student ID 3190704215

# 2. Topic requirements

Write a program that can automatically generate elementary school four arithmetic problems, and then expand on this basis:

1) In addition to integers, four arithmetic operations of true fractions are also supported, for example: 1/6+1/8=7/24

2) The program requires the ability to process user input, judge right or wrong, and accumulate points

3) Program support can be selected by the user for addition, subtraction, multiplication and division operations

4) Use the -n parameter to control the number of questions generated, for example Myapp.exe -n 10, will generate 10 questions

# 3. Code submission and running screenshots

```import random                      # random number
from fractions import Fraction     # operation of fractions

list_questions=[]                  # list of topics

num1 = random.randint(1, 100)         #Randomly generate two numbers
num2 = random.randint(1, 100)
chuli('+',num1,num2)

#subtraction
def cut():
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
if num1 < num2:
num1, num2 = num2, num1
chuli('-', num1, num2)

#multiplication
def mul():
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
chuli('*',num1,num2)

#division operation
def div():
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
chuli('÷',num1,num2)

#random operation
def rand_nums():
rule = random.choice(['+','-','*','÷'])        #random generation operator

elif rule == '-':                              #Generate subtraction questions, answers
cut()
elif rule == '*':                              #Generate multiplication questions and answers
mul()
div()

#True Fraction Operations
def frac():
fz1 = random.randint(1,10)    #Molecule 1
fm1 = random.randint(1,10)    #Denominator 1
if fz1 > fm1:
fz1,fm1 = fm1,fz1          # Guaranteed True Score
num1 = Fraction(fz1,fm1)       # Call Fraction to generate scores

fz2 = random.randint(1,10)      #Molecule 2
fm2 = random.randint(1,10)      #Denominator 2
if fz2 > fm2:
fz2,fm2 = fm2,fz2
num2 = Fraction(fz2,fm2)

if num1 < num2:
num1,num2 = num2,num1        # The result is guaranteed to be positive, except for division
rule = random.choice(['+','-','*','÷'])
chuli(rule,num1,num2)

# Extraction of methods for processing and storing questions
def chuli(flag, num1, num2):
list_questions.append(str(num1) + str(flag) + str(num2) + '=')  # Question, Answer Append to list
if (flag == '+'):
elif (flag == '-'):
elif (flag == '*'):
elif (flag == '÷'):
num = Fraction(num1, num2)

# Judge right or wrong and calculate the score
def judge():
count = 0         #Fractional value
for i in range(len(list_questions)):
print("the first{}question".format(i + 1))
print("topic:",list_questions[i])

print("----------------")
count += 1
else:
print("----------------")
return count

# Printing interface prompt information
def display():
print("------------------------Welcome to the applet for randomly generating four arithmetic operations------------------------")
print()
print("*********  2. Subtraction (-)")
print("*********  3. Multiplication ( x)")
print("*********  4. division operation (÷)")
print("*********  5. Random generation (randomly generate four operations)")
print("*********  6. True fraction operation (randomly generated four operations)")
print()
print("Tip: For inexhaustible numbers, fractions can be used: such as 1÷3 = 1/3,  13÷67 = 13/67")
print("---------------------------------------------------------------------------")

#main function
def main():
display()              #call display function

n = int(input("Please enter the number of questions:"))
print("----------------")
choose_rule = int(input("Please select an operation to perform(1-6): "))

for i in range(n):

if choose_rule == 1:
elif choose_rule == 2:
cut()
elif choose_rule == 3:
mul()
elif choose_rule == 4:
div()
elif choose_rule == 5:
rand_nums()
elif choose_rule == 6:
frac()
else:
break

count = judge()                           #Call the judge function, judge right or wrong, and score
rate = count/n
print("total{}points, a total of correct answers{}points, correct rate:{:.2f}%".format(n,count,rate*100))

main()         #main function call
```   # 4. Personal summary

psp2.1 Task content Time required to complete the plan (min) Time required to actually complete (min)
Planning plan 10 10
Estimate Estimate how much time this task will take and plan the approximate work steps 10 10
Development develop 120 110
Analysis Needs analysis (including learning new technologies) 15 10
Design Spec Generate design documentation 5 5
Design Review Design Review 5 5
Coding Standard code specification 3 2
Design specific design 10 15
Coding specific code 30 25
Code Review code review 5 7
Test Testing (self-testing, modifying code, committing changes) 10 15
Reporting Report 9 6
Test Report testing report 3 2
Size Measurement Computational workload 2 1
Postmortem & Process Improvement Plan Post-event summary and process improvement plan 3 3

When I saw this question, I went back to the elementary school, and chatted about the past like an essay naming it. The algorithms learned in those years may not be so easy to implement today through code (in fact, the skills are not good).
The first thought when I saw this question was to use the scientific computing language - Python, because it involves the operation of fractions. Compared with other programming languages, Python's support for mathematical operations may be better.
Secondly, Python is facing the end of the class. I want to experiment before the end of the class and try to use Python to perform some scientific calculations (in fact, the four arithmetic operations do not seem to be so high-end).
To sum up this programming, I have gained a lot. First of all, it is the python coding problem. Usually, I am too ambitious, just reading but not practicing, so emmmmm written in Python code, fortunately, I realized my shortcomings in time and corrected them in the future.
There is also the psp analysis, which has never been seen or heard in previous programming experience. Through this use, I have a clearer understanding of the programming process and my programming ability. There is a re-examination.
Finally, markdown syntax, there are always various problems when you change it, but it is best to grow up in various mistakes, and the finished product, as you can see.

Go to my homepage if you have time https://www.cnblogs.com/muyichenfeng/

Posted by socalnate on Mon, 09 May 2022 15:33:00 +0300