Requirements for this job see https://edu.cnblogs.com/campus/nenu/2019fall/homework/7631
Twinning partner: Luo Yang Meihui
- Development environment is windows
- Development tools are pycharm
- Python language version 3.7
- Git Version Control Selection
Function 1: four operations
Support the four operations subject title number 4, all of the questions asked have the ability to correctly answer (Hint:! = 1/3 0.33333333333333333333333333333333, but infinitely long).
For faster results, you quickly build a version of the console, including later changed into a better interface core functions, taking into account the expansion.
1.1 heavy and difficult
Can be listed in a random four arithmetic expressions, then receives the result of the calculation expression input by the user and answers and the correct result of the comparison. Function with the random number and the operation of the random function comes python obtain, using input () function of the input answers, and then eval Fraction into digital.
1.2 programming experience
In a moment realize the function takes a great deal of effort because various random functions need to access, while writing the state learn python, usually still have to accumulate when such use will not waste too much energy.
1.3 Important code shows
DEF Integer (): CH = [] # storage expression Number the random.randint = (. 1,. 5) # randomly generated number expression for I in Range (Number): RAND = the random.randint (0,. 1 ) A = func_integer (Number) # call expression generation function, an expression that produces IF RAND == 0: OP = Operation [the random.randint (0,3 )] RAND = the random.randint (0,. 1 ) IF ! I = Number -. 1 : IF rand == 0: ch.append('(') ch.append(a) ch.append(op) ch.append(random.randint(1,10)) ch.append(')') ch.append(operation[random.randint(0, 3)]) else: ch.append(a) ch.append(operation[random.randint(0, 3)]) else: ch.append(a) ch.append(operation[random.randint(0, 3)]) else: ch.append(a) ch.append(operation[random.randint(0, 3)]) kuohao = [] f = '' for k,i in enumerate(ch): if k != len(ch)-1: f += str(i) for i in f: if i.isdigit() == False: if i == '+': kuohao.append(0) elif i == '-': kuohao.append(1) elif i == '*': kuohao.append(2) elif i == '/': kuohao.append(3) else: kuohao.append(i) result_integer(f, ch, kuohao)
1.4 run shot
Function 2. Support brackets
The teacher looked at your performance, greatly appreciates you. Then she said, "Your exam is in how it questions without parentheses, brackets I remember you had to master Debu Well." You blush, the teacher said, "Give me two hours time, I you a new version, enclosed in parentheses. "
2.1 heavy and difficult
Generating parentheses, randomly generated by a function parentheses, brackets avoid useless.
2.2 programming experience
For the generation brackets, there are many problems to be solved, such as invalid parentheses solution that is relatively major priority parentheses and right parentheses sign the right symbols, brackets higher priority than the priority of the right of the right parenthesis symbol, was useless brackets .
By programming we found many problems, and to solve the problem continuously optimized.
2.3 Fragment
DEF Judge (F, CH): P1 = -1 # Left Left parenthesis symbol P2 = -1 # Right Right parenthesis symbol que = [] # determines whether each group of symbols useful, False is useless, True useful for K , I in the enumerate (CH): P = [] # stored sign in parentheses IF I == ' ( ' and K == 0: # began brackets for J in Range (. 1 , len (CH)): IF CH [J]! = ' ( ' and CH [J]! = ' )' And CH [J]> = 0: p.append (CH [J]) elif CH [J] == ' ) ' : for n- in Range (J +. 1 , len (CH)): IF CH [n-] ! = ' ) ' and CH [n-]> = 0: P2 = CH [n-] # sign right bracket BREAK the else : Continue BREAK the else : Continue IF len(p) == 1: if (p[-1] == 0 or p[-1] == 1) and (p2 == 0 or p2 == 1): que.append(False) elif (p[-1] == 2 or p[-1] == 3): que.append(False) else: que.append(True) if len(p) > 1: if p2 == 0 or p2 == 1: que.append(False) elif (p2 == 3 or P2 ==. 4) and (0 Not in P or . 1 Not in P): # when the sign of the right or right parentheses * /, que.append (False) # intermediate brackets no + or - sign was useless the else : que.append (True) IF I == ' ( ' and K =! 0: P1 = CH [K -. 1] # left parenthesis symbols left for J in Range (K +. 1 , len (CH)): IF CH [J]! =' ( ' And CH [J] =! ' ) ' And CH [J]> = 0: p.append (CH [J]) elif CH [J] == ' ) ' : IF ! J = len (CH) --1: # determines whether or not the right of the right parenthesis signed for n- in Range (J +. 1 , len (CH)): iF CH [n-] =! ' ) ' and CH [n-]> = 0: P2 = CH [n- ] # BREAK the else: Continue BREAK the else : P2 = -1 the else : Continue IF len (P). 1 == : IF P1 ==. 3: # the left of the left parenthesis is / are useful in parentheses que.append (True) elif P1 == 2 and (0 == P [-1] or . 1 == P [-1]): # left brackets *, the middle brackets - or +, useful bracket que.append (True) elif P1 ==. 1 and (0 P == [-1] or . 1 == P [-1]):# Left parenthesis -, intermediate brackets for the - or +, useful bracket que.append (True) elif P1 == 0 and (0 == P [-1] or . 1 == P [-1]) and ( ==. 3 P2 or P2 == 2 ): que.append (True) # left + parentheses, brackets intermediate - or +, * or to the right bracket / the else : que.append (False) # otherwise is useless bracket the else : IF p1 == 3: que.append (True) elif p1 == 1 and (1 in the p-or 0 in p): que.append(True) elif p1 == 2 and (0 in p or 1 in p): que.append(True) elif p1 == 0 and (0 in p or 1 in p) and (p2 == 3 or p2 ==2): que.append(True) else: que.append(False) return que
2.4 run shot
Features and functions to achieve a two screenshots
Function 4
Heavy and difficult: the function eval python may be an expression of the results, but the results may be fractional, may utilize a function library Fraction of fractons, outputs the result as a fraction of a full turn, so the same integer, decimal variable fraction. We do not fully operational to make the score can be solved only proper fraction, the result of the expression can turn into points
Code Screenshot:
def func_integer(number): f = '' ch = [] rand = random.randint(0, 1) if number != 1: if rand == 0: ch.append('(') op = operation[random.randint(0, 3)] ch.append(random.randint(1, 10)) ch.append(op) ch.append(random.randint(1, 10)) ch.append(')') else: op = operation[random.randint(0, 3)] if op == '/': a = random.randint(1, 10) ch.append(a) ch.append(op) ch.append(random.randint(a, 10)) else: ch.append(random.randint(1, 10)) ch.append(op) ch.append(random.randint(1, 10)) else: op = operation[random.randint(0, 3)] if op == '/': a = random.randint(1, 10) ch.append(a) ch.append(op) ch.append(random.randint(a, 10)) else: ch.append(random.randint(1, 10)) ch.append(op) ch.append(random.randint(1, 10))
= n- the eval (F) n- = Fraction ( ' {} ' .format (n-)). limit_denominator () # The result of the expression is converted into score
Five events take a long time
(1) When we produce what language differences, Luo Yang Meihui students are good at using the Java language, I think python relatively easy to use, although not as familiar with JAVA, but we can learn while knocking code. Finally, select the python.
(2) When we select a random functions and applications, because they do not familiar with the python library to find information using for a long time.
(3) When we do parenthesis function, we found that many brackets useless, it takes a long time to solve this problem.
(4) For pair programming, we clear division of labor, improve efficiency, let me gain unity is strength.
(5) to find a test case analysis Bug takes a long time, considered in many cases.
Six photos
Location: Dominic apartment B320
Computer: Xu Lijun students notebook
Seven version control
https://e.coding.net/xulijun/sizeyunsuan.git