mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-09 05:36:22 +08:00
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -20,49 +20,49 @@ Enter a Postfix Equation (space separated) = 5 6 9 * +
|
||||
import operator as op
|
||||
|
||||
|
||||
def Solve(Postfix):
|
||||
Stack = []
|
||||
Div = lambda x, y: int(x / y) # noqa: E731 integer division operation
|
||||
Opr = {
|
||||
def solve(post_fix):
|
||||
stack = []
|
||||
div = lambda x, y: int(x / y) # noqa: E731 integer division operation
|
||||
opr = {
|
||||
"^": op.pow,
|
||||
"*": op.mul,
|
||||
"/": Div,
|
||||
"/": div,
|
||||
"+": op.add,
|
||||
"-": op.sub,
|
||||
} # operators & their respective operation
|
||||
|
||||
# print table header
|
||||
print("Symbol".center(8), "Action".center(12), "Stack", sep=" | ")
|
||||
print("-" * (30 + len(Postfix)))
|
||||
print("-" * (30 + len(post_fix)))
|
||||
|
||||
for x in Postfix:
|
||||
for x in post_fix:
|
||||
if x.isdigit(): # if x in digit
|
||||
Stack.append(x) # append x to stack
|
||||
stack.append(x) # append x to stack
|
||||
# output in tabular format
|
||||
print(x.rjust(8), ("push(" + x + ")").ljust(12), ",".join(Stack), sep=" | ")
|
||||
print(x.rjust(8), ("push(" + x + ")").ljust(12), ",".join(stack), sep=" | ")
|
||||
else:
|
||||
B = Stack.pop() # pop stack
|
||||
b = stack.pop() # pop stack
|
||||
# output in tabular format
|
||||
print("".rjust(8), ("pop(" + B + ")").ljust(12), ",".join(Stack), sep=" | ")
|
||||
print("".rjust(8), ("pop(" + b + ")").ljust(12), ",".join(stack), sep=" | ")
|
||||
|
||||
A = Stack.pop() # pop stack
|
||||
a = stack.pop() # pop stack
|
||||
# output in tabular format
|
||||
print("".rjust(8), ("pop(" + A + ")").ljust(12), ",".join(Stack), sep=" | ")
|
||||
print("".rjust(8), ("pop(" + a + ")").ljust(12), ",".join(stack), sep=" | ")
|
||||
|
||||
Stack.append(
|
||||
str(Opr[x](int(A), int(B)))
|
||||
stack.append(
|
||||
str(opr[x](int(a), int(b)))
|
||||
) # evaluate the 2 values popped from stack & push result to stack
|
||||
# output in tabular format
|
||||
print(
|
||||
x.rjust(8),
|
||||
("push(" + A + x + B + ")").ljust(12),
|
||||
",".join(Stack),
|
||||
("push(" + a + x + b + ")").ljust(12),
|
||||
",".join(stack),
|
||||
sep=" | ",
|
||||
)
|
||||
|
||||
return int(Stack[0])
|
||||
return int(stack[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Postfix = input("\n\nEnter a Postfix Equation (space separated) = ").split(" ")
|
||||
print("\n\tResult = ", Solve(Postfix))
|
||||
print("\n\tResult = ", solve(Postfix))
|
||||
|
Reference in New Issue
Block a user