Hướng dẫn bodmas-calculator in python - máy tính bodmas trong python

Một thẻ đã tồn tại với tên chi nhánh được cung cấp. Nhiều lệnh GIT chấp nhận cả tên thẻ và tên chi nhánh, vì vậy việc tạo nhánh này có thể gây ra hành vi bất ngờ. Bạn có chắc là bạn muốn tạo chi nhánh này?

ifyis '^':

Numlist [x] = float (Numlist [x]) ** Numlist [x+1]

Numlist.Remove (Numlist [x+1])

ClassCalculator: Calculator:
def__init __ (tự, đầu vào): __init__(self, Input):
Input = input.replace ("", "") #removing không gian để làm cho nó ít phức tạp hơn. = Input.replace(" ", "") #Removing spaces to make it less complicated.
InputList = [yforx, yinenumerate (đầu vào)] = [y for x,y in enumerate(Input)] #Making a list of all letters of the Input.. For Example 2+2 = ['2', '+', '2']
tự.numlist = [].numList = []
self.oplist = [] #op là viết tắt của người vận hành.opList = [] #op stands for operator
self.tempNum=''.tempNum = ''
self.n = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'] # Các ký tự được chấp nhận cho đầu vào dưới dạng một số..N = ['1','2','3','4','5','6','7','8','9','0', '.'] #Accepted Characters for input as a number.
Numlist, oplist = self.formNumber (InputList) # SPLING INPUTLIST thành NUMLIST, OPLIST CHO EG, 2+2, NUMLIST = ['2', '2'] oplist = ['+'], opList = self.formNumber(inputList) # Splitting inputList into numList, opList for eg, 2+2, numList = ['2', '2'] opList = ['+']
Danh sách, oplist = self.solve (danh sách, danh sách oplist), opList = self.solve(numList, opList)
trong khi ('+' inpoplist) hoặc ('-'inoplist) hoặc ('*'inpoplist) hoặc ('/'inoplist) hoặc ('^'inoplist): ('+' in opList) or ('-' in opList) or ('*' in opList) or ('/' in opList) or ('^' in opList):
Danh sách, oplist = self.solve (danh sách, danh sách oplist), opList = self.solve(numList, opList)
trong khi ('+' inpoplist) hoặc ('-'inoplist) hoặc ('*'inpoplist) hoặc ('/'inoplist) hoặc ('^'inoplist):.result = numList[0]
self.Result = Numlist [0] solveBrackets(self, Input):
defsolveBrackets (tự, đầu vào): = [y for x,y in enumerate(Input)]
InputList = [yforx, yinenumerate (đầu vào)], opList = [], []
tempNum='' = ''
Danh sách, oplist = [], [] y,x in enumerate(inputList):
Fory, Xinenumerate (Inputlist): str(x) in self.N:
ifstr (x) inself.n: += str(x)
tempnum+= str (x):
khác: tempNum != '':
iftempnum! = '':.append(float(tempNum))
tempNum='' = ''
Numlist.Append (Float (Tempnum)).append(x)
oplist.append (x) y+1 is len(inputList):
khác: tempNum != '':
iftempnum! = '':.append(float(tempNum))
tempNum='' = ''
Danh sách, oplist = self.solve (danh sách, danh sách oplist), opList = self.solve(numList, opList)
trong khi ('+' inpoplist) hoặc ('-'inoplist) hoặc ('*'inpoplist) hoặc ('/'inoplist) hoặc ('^'inoplist): ('+' in opList) or ('-' in opList) or ('*' in opList) or ('/' in opList) or ('^' in opList):
Danh sách, oplist = self.solve (danh sách, danh sách oplist), opList = self.solve(numList, opList)
trong khi ('+' inpoplist) hoặc ('-'inoplist) hoặc ('*'inpoplist) hoặc ('/'inoplist) hoặc ('^'inoplist): numList[0]
self.Result = Numlist [0] formNumber(self, inputList):
tempNum='' = ''
defsolveBrackets (tự, đầu vào): = []
InputList = [yforx, yinenumerate (đầu vào)] = []
brackets=False = False
Danh sách, oplist = [], [] y,x in enumerate(inputList):
Fory, Xinenumerate (Inputlist): str(x) is '(':
brackets=True = True
continue
ifstr (x) inself.n: str(x) is ')':
brackets=False = False
tempnum+= str (x) = self.solveBrackets(tempNum)
khác:.append(tempNum)
continue
iftempnum! = '': brackets:
ifstr (x) inself.n: += str(x)
tempnum+= str (x):
Fory, Xinenumerate (Inputlist): str(x) in self.N:
ifstr (x) inself.n: = tempNum + str(x)
tempnum+= str (x):
khác: tempNum != '':
iftempnum! = '':.append(float(tempNum))
tempNum='' = ''
Numlist.Append (Float (Tempnum)).append(x)
oplist.append (x) y+1 is len(inputList):
iftempnum! = '':.append(float(tempNum))
tempNum='' = ''
Numlist.Append (Float (Tempnum)) numList, opList
oplist.append (x) solve(self, numList, opList):
ify+1islen (InputList): x,y in enumerate(opList):
returnNumList [0] y is '^':
defformnumber (self, inputlist):[x] = float(numList[x]) ** numList[x+1]
Numlist = [].remove(numList[x+1])
oplist = [].remove(y)
ify+1islen (InputList): x,y in enumerate(opList):
returnNumList [0] y is '/':
defformnumber (self, inputlist):[x] = float(numList[x]) / numList[x+1]
Numlist = [].remove(numList[x+1])
oplist = [].remove(y)
ify+1islen (InputList): x,y in enumerate(opList):
returnNumList [0] y is '*':
defformnumber (self, inputlist):[x] = float(numList[x]) * numList[x+1]
Numlist = [].remove(numList[x+1])
oplist = [].remove(y)
ify+1islen (InputList): x,y in enumerate(opList):
returnNumList [0] y is '+':
defformnumber (self, inputlist):[x] = float(numList[x]) + numList[x+1]
Numlist = [].remove(numList[x+1])
oplist = [].remove(y)
ify+1islen (InputList): x,y in enumerate(opList):
returnNumList [0] y is '-':
defformnumber (self, inputlist):[x] = float(numList[x]) - numList[x+1]
Numlist = [].remove(numList[x+1])
oplist = [].remove(y)
Numlist.Append (Float (Tempnum)) numList, opList
oplist.append (x) True:
ify+1islen (InputList)::
returnNumList [0] = Calculator(raw_input("Enter An Equation: ")) #You may need to change raw_input to input if you are using python 3
defformnumber (self, inputlist):(cal.result)
Numlist = []:
oplist = []("Sorry There's an error")