1006. Clumsy Factorial - notruilin/LeetCode GitHub Wiki

  1. Eval: "evaluates the specified expression, if the expression is a legal Python statement, it will be executed"

The parameter should be a string

>>> eval('10 // 2 - 1 * 2')
3
>>> x = 2333
>>> eval('x + 123')
2456

() can be used to change the priority

>>> eval('(1 + (1 + 2)) * 3')
12
  1. //: “floor” division
>>> 2.0/3.0
0.6666666666666666
>>> 2.0//3.0
0.0
  1. Please Please Please stop coding like this...
op = ['*','/','+','-']
i = 0
while N:
    ......
    i += 1
    if i == 4:  i = 0
    N -= 1
   ⬇️
op = ['*','/','+','-']
for i in range(N-1, 0, -1):
    if op[(N-i)%4] == '*':
        ......