예제 #1
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except (SyntaxError, ZeroDivisionError, TypeError):
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()
        elif key in constantList:
            Conlist = ['3.141592', '3E+8', '340', '1.5E+8']
            for i in range(4):
                if key == constantList[i]:
                    self.display.setText(self.display.text() + Conlist[i])
        elif key in functionList:
            n = self.display.text()
            Funlist = [
                calcFunctions.factorial(n),
                calcFunctions.decToBin(n),
                calcFunctions.binToDec(n),
                calcFunctions.decToRoman(n)
            ]
            for i in range(4):
                if key == functionList[i]:
                    value = Funlist[i]
                    self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
예제 #2
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()
        elif key in constantList:
            for value in constantList.values():
                self.display.setText(self.display.text() + value)
        elif key in functionList:
            n = self.display.text()
            if key == functionList[0]:
                value = calcFunctions.factorial(n)
            elif key == functionList[1]:
                value = calcFunctions.decToBin(n)
            elif key == functionList[2]:
                value = calcFunctions.binToDec(n)
            elif key == functionList[3]:
                value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
예제 #3
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()

        elif key in constantDict.keys():
            self.display.setText(self.display.text() + constantDict[key])
        elif key in functionList:
            n=self.display.text()
            functionDict = {'factorial (!)': calcFunctions.factorial(n),
                            '-> binary': calcFunctions.decToBin(n),
                            'binary -> dec': calcFunctions.binToDec(n),
                            '-> roman': calcFunctions.decToRoman(n)}

            value=functionDict[key]
            self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
예제 #4
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        #for문 등 반복문 사용하여 코드 개선(강의노트 참고)

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()
        # elif key == constantList[0]:
        #     self.display.setText(self.display.text() + '3.141592')
        # elif key == constantList[1]:
        #     self.display.setText(self.display.text() + '3E+8')
        # elif key == constantList[2]:
        #     self.display.setText(self.display.text() + '340')
        # elif key == constantList[3]:
        #     self.display.setText(self.display.text() + '1.5E+8')

        for i in constantDic.keys():
            if key == i:
                self.display.setText(constantDic[i])

        # for i in functionList.keys():
        #     if key == functionList[i]:
        #         n = self.display.text()
        #         value = calcFunctions.functionList[i]
        #         self.display.setText(str(value))
        #
        #
        # else:
        #     self.display.setText(self.display.text() + key)

        if key == functionList[0]:
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
    def buttonClicked(self):
        constant = ['3.1451592','3E+8','340','1.5E+8']
        functions = [calcFunctions.factorial(self.display.text()),
                     calcFunctions.decToBin(self.display.text()),
                     calcFunctions.binToDec(self.display.text()),
                     calcFunctions.decToRoman(self.display.text())]


        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
                self.display.clear()
        elif key in constantList:
            for i in range(4):
                if key == constantList[i]:
                    self.display.setText(self.display.text() + constant[i])
        elif key in functionList:
            for i in range(4):
                if key == functionList[i]:
                    value = functions[i]
                    self.display.setText(str(value))

        #elif key == constantList[0]:
        #    self.display.setText(self.display.text() + '3.141592')
        #elif key == constantList[1]:
        #    self.display.setText(self.display.text() + '3E+8')
        #elif key == constantList[2]:
        #    self.display.setText(self.display.text() + '340')
        #elif key == constantList[3]:
        #    self.display.setText(self.display.text() + '1.5E+8')
        #elif key == functionList[0]:
        #    n = self.display.text()
        #    value = calcFunctions.factorial(n)
        #    self.display.setText(str(value))
        #elif key == functionList[1]:
        #    n = self.display.text()
        #    value = calcFunctions.decToBin(n)
        #    self.display.setText(str(value))
        #elif key == functionList[2]:
        #    n = self.display.text()
        #    value = calcFunctions.binToDec(n)
        #    self.display.setText(str(value))
        #elif key == functionList[3]:
        #    n = self.display.text()
        #    value = calcFunctions.decToRoman(n)
        #   self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
예제 #6
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':

            try:
                result = str(eval(self.display.text()))

            except:
                result = 'Error!'

            self.display.setText(result)

        elif key == 'C':
            self.display.clear()

        elif key in constantList:

            try:
                consList = ['3.141592', '3E+8', '340', '1.5E+8']

                for idx in range(0, 4):

                    if key in constantList[idx]:

                        self.display.setText(self.display.text() +
                                             consList[idx])

            except:
                "Error"

        elif key in functionList:

            try:

                n = str(eval(self.display.text()))

                calcList = [
                    calcFunctions.factorial(n),
                    calcFunctions.decToBin(n),
                    calcFunctions.binToDec(n),
                    calcFunctions.decToRoman(n)
                ]

                for idx in range(4):

                    if key in functionList[idx]:

                        self.display.setText(calcList[idx])
            except:
                "Error"

        else:
            self.display.setText(self.display.text() + key)
예제 #7
0
    def buttonClicked(self):

        operator = ['*', '+', '-', '.', '/']

        if self.display.text() == 'Error!':
            self.display.setText('')

        elif self.display.text() == "0으로 나눌 수 없습니다.":
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except ZeroDivisionError:
                result = "0으로 나눌 수 없습니다."
            except:
                result = "Error!"
            self.display.setText(result)

        elif key == 'C':
            self.display.clear()

        elif self.display.text() == '' and key in operator:
            pass

        elif self.display.text() != '' and self.display.text()[-1] in operator:
            if self.display.text()[-1] == '*' and self.display.text()[-2] != '*' and key == '*':
                self.display.setText(self.display.text() + key)

            elif self.display.text()[-1] == '/' and self.display.text()[-2] != '/' and key == '/':
                self.display.setText(self.display.text() + key)

            elif key not in operator:
                self.display.setText(self.display.text() + key)

        elif key in constantList:
            ftion = ['3.141592', '3E+8', '340', '1.5E+8']
            for calclist in range(0, 4):
                if key in constantList[calclist]:
                    self.display.setText(self.display.text() + ftion[calclist])

        elif key in functionList:
            n = eval(self.display.text())
            val = [calcFunctions.factorial(n), calcFunctions.decToBin(n),
                   calcFunctions.binToDec(n), calcFunctions.decToRoman(n)]
            for calcftion in range(0, 4):
                if key in functionList[calcftion]:
                    value = val[calcftion]
                    self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
예제 #8
0
def functionOperator(key, display):
    if key == functionList[0]:
        return str(calcFunctions.factorial(display))

    elif key == functionList[1]:
        return str(calcFunctions.decToBin(display))

    elif key == functionList[2]:
        return str(calcFunctions.binToDec(display))

    elif key == functionList[3]:
        return str(calcFunctions.decToRoman(display))
예제 #9
0
    def buttonClicked(self):
        try:

            if self.display.text() == 'Error!':
                self.display.setText('')

            button = self.sender()
            key = button.text()

            if key == '=':
                result = str(eval(self.display.text()))
                # 부동소수를 처리해준 값을 리턴해줍니다!
                self.display.setText(calcFunctions.floatPoint(result))

            elif key == 'C':
                self.display.setText('')

            elif key == constantList[0]:  # Pi
                self.display.setText(self.display.text() + '3.141592')

            elif key == constantList[1]:  # 빛의 이동 속도
                self.display.setText(self.display.text() + '3E+8')

            elif key == constantList[2]:  # 소리의 이동 속도
                self.display.setText(self.display.text() + '340')

            elif key == constantList[3]:  # 태양과의 평균 거리
                self.display.setText(self.display.text() + '1.5E+8')

            elif key == functionList[0]:  # Factorial
                n = self.display.text()
                value = calcFunctions.factorial(n)
                self.display.setText(str(value))

            elif key == functionList[1]:  # dec -> binary
                n = self.display.text()
                value = calcFunctions.decToBin(n)
                self.display.setText(str(value))

            elif key == functionList[2]:  # binary -> dec
                n = self.display.text()
                value = calcFunctions.binToDec(n)
                self.display.setText(str(value))

            elif key == functionList[3]:  # dec -> roman
                n = self.display.text()
                value = calcFunctions.decToRoman(n)
                self.display.setText(str(value))
            else:
                self.display.setText(self.display.text() + key)
        except:
            pass
예제 #10
0
    def buttonClicked(self):
        # 만약 버튼이 눌었을 때 결과창에 나타나는값 구동 함수
        #num = eval(self.display.text()) #이거 왜 따로 객체를 못만들지???

        # 만약 결과창에 Error!가 뜨면 초기화 한다.
        if self.display.text() == 'Error!':
            self.display.setText('')

        # 버튼이 눌었을 때 날라오는 두 가지 이름 정하기
        button = self.sender()  # 날라오는 값???
        key = button.text()  # button 겉에 쓰여 있는 표시 / 숫자 누를때는 바로 사용가능

        if key == numPadList[11]:
            try:
                result = str(eval(
                    self.display.text()))  # 결과값창의 것을 계산이 후 스트링변화 -> result
            except:
                result = 'Error!'
            self.display.setText(result)  # 결과 값을 창에 넣는다.

        elif key == operatorList[6]:
            self.display.clear()


#index(key)를 사용해서 한줄로 표현 하기
# elif  ==   (x for in) :
        elif [True for x in constantList if key == x]:
            btTcon = [x for x in range(0, 4)
                      if key == constantList[x]]  # constantList이 눌렸을 때
            result_con = str(btTcon)[1]  # 리스트에서 스트링으로 바꾸기
            text_list = ['3.141592', '3E+8', '340', '1.5E+8']
            self.display.setText(self.display.text() +
                                 text_list[int(result_con)])

        elif [True for x in functionList if key == x]:
            result_text = eval(self.display.text())
            btTfun = [x for x in range(0, 4)
                      if key == functionList[x]]  # functionList이 눌렸을 때
            result_fun = str(btTfun)[1]  # 리스트에서 스트링으로 바꾸기
            result_list = [
                calcFunctions.factorial(result_text),
                calcFunctions.decToBin(result_text),
                calcFunctions.binToDec(str(result_text)),
                calcFunctions.decToRoman(result_text)
            ]
            # str bin-> int

            value = result_list[int(result_fun)]
            self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
예제 #11
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()
        elif key == constantList[0]:
            self.display.setText(self.display.text() + '3.141592')
        elif key == constantList[1]:
            self.display.setText(self.display.text() + '3E+8')
        elif key == constantList[2]:
            self.display.setText(self.display.text() + '340')
        elif key == constantList[3]:
            self.display.setText(self.display.text() + '1.5E+8')
        elif key == functionList[0]:
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        #수정한 부분
        elif key == functionList[4]:
            n = self.display.text()
            value = calcFunctions.RomanTodec(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
예제 #12
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                num = eval(self.display.text())
                result = calcFunctions.fixThefloatpoint(num)
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == '<-':
            result = self.display.text()
            self.display.setText(result[0:len(result) - 1])
        elif key == 'C':
            self.display.clear()
        elif key == 'pi':
            self.display.setText(self.display.text() + '3.141592')
        elif key == '빛의 이동 속도 (m/s)':
            self.display.setText(self.display.text() + '3E+8')
        elif key == '소리의 이동 속도 (m/s)':
            self.display.setText(self.display.text() + '340')
        elif key == '태양과의 평균 거리 (km)':
            self.display.setText(self.display.text() + '1.5E+8')
        elif key == 'factorial (!)':
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
        elif key == '-> binary':
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == 'binary -> dec':
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == '-> roman':
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
예제 #13
0
    def buttonClicked(self):
        if self.error:
            self.display.clear()
            self.error = False

        button = self.sender()
        key = button.text()

        ConstantGroups = {
            'pi': '3.141592',
            '빛의 이동 속도 (m/s)': '3E+8',
            '소리의 이동 속도 (m/s)': '340',
            '태양과의 평균 거리 (km)': '1.5E+8'
        }

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
                self.error = True
            self.display.setText(result)

        elif key == 'C':
            self.display.clear()

        elif key in constantList:
            self.display.setText(self.display.text() + ConstantGroups[key])

        elif key == functionList[0]:
            n = self.display.text()
            value = factorial(n)
            self.display.setText(str(value))

        elif key == functionList[1]:
            n = self.display.text()
            value = decToBin(n)
            self.display.setText(str(value))

        elif key == functionList[2]:
            n = self.display.text()
            value = binToDec(n)
            self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
예제 #14
0
def function(calc, key) :
    if key == 'factorial (!)':
        n = calc.display.text()
        value = calcFunctions.factorial(n)
        calc.display.setText(str(value))
    elif key == '-> binary':
        n = calc.display.text()
        value = calcFunctions.decToBin(n)
        calc.display.setText(str(value))
    elif key == 'binary -> dec':
        n = calc.display.text()
        value = calcFunctions.binToDec(n)
        calc.display.setText(str(value))
    elif key == '-> roman':
        n = calc.display.text()
        value = calcFunctions.decToRoman(n)
        calc.display.setText(str(value))
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        #리스트 생성
        consList = {
            'pi': 3.141592,
            '빛의 이동 속도 (m/s)': 3E+8,
            '소리의 이동 속도 (m/s)': 340,
            '태양과의 평균 거리 (km)': 1.5E+8
        }
        funcList = {
            'factorial (!)': calcFunctions.factorial(self.display.text()),
            '-> binary': calcFunctions.decToBin(self.display.text()),
            'binary -> dec': calcFunctions.binToDec(self.display.text()),
            '-> roman': calcFunctions.decToRoman(self.display.text())
        }

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()

        elif key in consList.keys():
            for conskey in consList.keys():
                if key == conskey:
                    self.display.setText(self.display.text() +
                                         str(consList[key]))

        elif key in funcList.keys():
            for funckey in funcList.keys():
                if key == funckey:
                    value = funcList[key]
                    self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            self.getResult()

        elif key == 'C':
            self.display.clear()
        elif key == constantList[0]:
            self.display.setText(self.display.text() + '3.141592')
        elif key == constantList[1]:
            self.display.setText(self.display.text() + '3E+8')
        elif key == constantList[2]:
            self.display.setText(self.display.text() + '340')
        elif key == constantList[3]:
            self.display.setText(self.display.text() + '1.5E+8')
        elif key == functionList[0]:
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = float(self.display.text())
            value = math.cos(n)
            self.display.setText(str(value))
        elif key == functionList[4]:
            n = float(self.display.text())
            value = math.sin(math.degrees(n))
            self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
예제 #17
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()
        constFunc = lambda x: self.display.setText(self.display.text() + x)
        constValues = {
            constantList[0]: '3.141592',
            constantList[1]: '3E+8',
            constantList[2]: '340',
            constantList[3]: '1.5E8',
        }

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()
        elif key in constValues.keys():
            constFunc(constValues[key])
        elif key == functionList[0]:
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
예제 #18
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = calcFunctions.incorrectFloat(self.display.text())
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()
        elif key == constantList[0]:
            self.display.setText(self.display.text() + '(3.141592)')
        elif key == constantList[1]:
            self.display.setText(self.display.text() + '(3E+8)')
        elif key == constantList[2]:
            self.display.setText(self.display.text() + '(340)')
        elif key == constantList[3]:
            self.display.setText(self.display.text() + '(1.5E+8)')
        elif key == functionList[0]:
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
예제 #19
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            # 0으로 나눴을 때 예외처리
            except ZeroDivisionError:
                result = '0으로 나눌 수 없습니다'
            except:
                result = 'Error!'
            self.display.setText(result)

        elif key == 'C':
            self.display.clear()
        # 반복을 줄임
        elif key in constantDic:
            self.display.setText(constantDic[key])
        # function도 딕셔너리를 통해 반복을 줄이고 싶었으나 실패함
        elif key in functionList[0]:
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)
예제 #20
0
    def buttonClicked(self):

        self.count = 0
        list1 = ["3.141592", "3E+8", "340", "1.5E+8", "2.718281"]
        if self.display.text() == 'Error!' or self.display.text() == '0':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if self.count == 1:
            self.display.setText('')
            self.count = 0

        if key == '=':
            try:
                result = str(eval(self.display.text()))
                self.count += 1
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.setText('0')
        elif key in constantList:
            for i in range(0, len(list1)):
                if key == constantList[i]:
                    self.display.setText(self.display.text() + list1[i])
        elif key in functionList:
            n = self.display.text()
            if key == functionList[0]:
                value = calcFunctions.factorial(n)
            elif key == functionList[1]:
                value = calcFunctions.decToBin(n)
            elif key == functionList[2]:
                value = calcFunctions.binToDec(n)
            elif key == functionList[3]:
                value = calcFunctions.decToRoman(n)
            elif key == functionList[4]:
                value = calcFunctions.squareRoot(n)
            self.display.setText((str(value)))
        else:
            self.display.setText(self.display.text() + key)
예제 #21
0
    def buttonClicked(self):
        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        flag = False

        contents = {0: '3.141592', 1: '3E+8', 2: '340', 3: '1.5E+8'}
        n = self.display.text()

        function_dic = {0: calcFunctions.factorial(n), 1: calcFunctions.decToBin(n),
                        2: calcFunctions.binToDec(n), 3: calcFunctions.decToRoman(n)}

        for idx in range(4):
            if key == constantList[idx]:
                self.display.setText(self.display.text() + contents[idx])
                flag = True


        for idx in range(4):
            if key == functionList[idx]:
                value = function_dic[idx]
                self.display.setText(str(value))
                flag = True

        if not flag:
            if key == '=':
                try:
                    result = str(eval(self.display.text()))
                except:
                    result = 'Error!'
                self.display.setText(result)

            elif key == 'C':
                self.display.clear()

            else:
                self.display.setText(self.display.text() + key)
예제 #22
0
    def buttonClicked(self):
        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)

        elif key == 'C':
            self.display.clear()

        elif key in constantList:  #for문과 list를 사용하여 단축
            conLi = ['3.141592', '3E+8', '340', '1.5E+8']
            for i in range(4):
                if key == constantList[i]:
                    self.display.setText(self.display.text() + conLi[i])

        elif key in functionList:  #for문과 리스트를 사용하여 단축
            n = self.display.text()
            fun = [
                calcFunctions.factorial(n),
                calcFunctions.decToBin(n),
                calcFunctions.binToDec(n),
                calcFunctions.decToRoman(n)
            ]  #getattr 사용해서 단축 가능
            for i in range(4):
                if key == functionList[i]:
                    value = fun[i]
                    self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
예제 #23
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()

        for i in constantList.keys():
            if key == i:
                self.display.setText(constantList[i])

        for j in range.functionList(0, 4):
            if functionList[j]:
                n = self.display.text()
                fun = [
                    calcFunctions.factorial(n),
                    calcFunctions.decToBin(n),
                    calcFunctions.binToDec(n),
                    calcFunctions.decToRoman(n)
                ]
                value = fun[j]
                self.display.setText(str(value))
            elif key == 'C':
                self.display.clear()

        else:
            self.display.setText(self.display.text() + key)
예제 #24
0
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')
     
        button = self.sender()
        key = button.text()

        #추가 리스트
        numList = {'pi' : 3.141592,'빛의 이동 속도 (m/s)' : 3E+8,'소리의 이동 속도 (m/s)' : 340,'태양과의 평균 거리 (km)' : 1.5E+8}
        performList = {'factorial (!)' : calcFunctions.factorial(self.display.text()),'-> binary' : calcFunctions.decToBin(self.display.text()),
                       'binary -> dec': calcFunctions.binToDec(self.display.text()),'dec -> roman' : calcFunctions.decToRoman(self.display.text()),'roman -> dec' : calcFunctions.RomanTodec(self.display.text())}

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()

        #줄인 코드 1
        elif key in numList.keys():
            for numkey in numList.keys():
                if key == numkey:
                    self.display.setText(self.display.text() + str(numList[key]))
        #줄인 코드 2
        elif key in performList.keys():
            for performkey in performList.keys():
                if key == performkey:
                    value = performList[key]
                    self.display.setText(str(value))


        else:
            self.display.setText(self.display.text() + key)
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
        elif key == 'C':
            self.display.clear()

        elif key in constantList:
            keyIndex = constantList.index(key)
            self.display.setText(self.display.text() +
                                 constantResult[keyIndex])

        elif key in functionList:
            n = eval(self.display.text())
            functionResult = [
                calcFunctions.factorial(n),
                calcFunctions.decToBin(n),
                calcFunctions.binToDec(n),
                calcFunctions.decToRoman(n)
            ]
            keyIndex = functionList.index(key)
            value = functionResult[keyIndex]
            self.display.setText(str(value))

        else:
            self.display.setText(self.display.text() + key)
    def buttonClicked(self):
        self.flagCheck()
        button = self.sender()
        key = button.text()

        if key == "=":
            try:
                result = str(eval(self.display.text()))
            except:
                result = "Error!"
                self.display.setText(result)
                self.flag = "error"
            else:
                self.display.setText(result)

        elif key == "C":
            self.display.clear()
            self.flag = ""

        elif key in constantList:
            if self.flag != "number" and self.flag != "constant":
                idx = constantList.index(key)
                self.display.setText(self.display.text() + constantValueList[idx])
                self.flag = "constant"

        elif key == functionList[0]:
            if self.display.text() != "":
                n = eval(self.display.text())
                if isinstance(n, int):
                    if 0 <= int(n) <= 17:
                        value = factorial(int(n))
                        self.flag = "number"
                    else:
                        value = 'Error!'
                        self.flag = "error"
                else:
                    value = 'Error!'
                    self.flag = "error"
            else:
                value = 'Error!'
                self.flag = "error"
            self.display.setText(str(value))
        elif key == functionList[1]:
            if self.display.text() != "":
                n = str(eval(self.display.text()))
                value = calcFunctions.decToBin(n)
                if len(value) > 15:
                    value = "Too long"
                    self.flag = "error"
                else:
                    self.flag = "bin"
            else:
                value = 'Error!'
                self.flag = "error"
            self.display.setText(str(value))

        elif key == functionList[2]:
            if self.display.text() != "":
                n = str(eval(self.display.text()))
                value = calcFunctions.binToDec(n)
                if value == "Error!":
                    self.flag = "error"
                else:
                    self.flag = "number"
            else:
                value = 'Error!'
                self.flag = "error"
            self.display.setText(str(value))

        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        elif key in operatorList:
            if self.flag == "bin":
                pass
            elif key == "(" or key == ")":
                self.display.setText(self.display.text() + key)
            elif self.flag != "operator":
                self.display.setText(self.display.text() + key)
                self.flag = "operator"

        else:
            self.flagCheck()
            if self.flag != "constant" and self.flag != "bin":
                if self.display.text() == "0":
                    if key == "0":
                        pass
                    elif key == ".":
                        self.display.setText(self.display.text() + key)
                    else:
                        self.display.setText(key)
                elif key == ".":
                    if "." in self.display.text():
                        pass
                    elif self.display.text() == "":
                        pass
                    else:
                        self.display.setText(self.display.text() + key)
                else:
                    self.display.setText(self.display.text() + key)
                self.flag = "number"
        print(self.flag)
예제 #27
0
파일: 20171660.py 프로젝트: tkdgusis4/team5
    def buttonClicked(self):
        if 'clear' in init:
            self.display.clear()
            init.clear()

        button = self.sender()
        key = button.text()

        ## 06 + 3처럼 앞에 0이 있을 경우 에러처리가 나던 것을 처리하기 위해
        ## 맨앞에 0이 나타나지 않을때까지 0을 지우고 연산기호 뒤의 문자도 0이면 없애는 식으로 하려했으나
        ## 연산기호를 여러번 쓰는부분을 어떻게 코딩해야할지 몰라 남겼습니다.
        '''idx = 0
        if key == '=':
            if '+' or '-' or '*' or '/' in self.display.text():
                del0 = ''
                for i in range(1, len(self.display.text())):
                # 연산기호가 몇번째에 있는 지 확인
                    if self.display.text()[i] == '+':
                        idx = i
                    if self.display.text()[i] == '-':
                        idx = i
                    if self.display.text()[i] == '*':
                        idx = i
                    if self.display.text()[i] == '/':
                        idx = i

                del1 = ''
                ## 첫째 인자에 0이 있는 경우
                count = 1
                print(idx)
                while self.display.text()[0] == '0':
                    count += 1
                    # 첫째 인자 0제거
                    for i in range(1, len(self.display.text())):
                        del0 += self.display.text()[i]
                    self.display.setText(del0)
                    # 둘째 인자 0 유무 확인
                    while del0[idx + 1] == '0':
                    # 0이 있네?
                        for i in range(1, len(del0)):
                            if i == idx:
                                continue
                            else:
                                del1 += del0[i]
                        self.display.setText(del1)
                    # 둘째 인자에 0이 없는 경우
                    else:
                        self.display.setText(str(eval(del0)))

                ## 첫재 인자에 0이 없는우 경우
                else:
                    ## 둘째 인자에 0이 있는 경우
                    if self.display.text()[idx + 1] == 0:
                        print('22')

                    ## 둘째 인장에 0이 없는 경우
                    else:
                        try:
                            result = str(eval(self.display.text()))
                        except:
                            result = 'Error!'
                        self.display.setText(result)'''
        if key == '=':

            ## 계산 입력 후 값 초기화를 위해 init라는 리스트를 생성
            ## ZeroDivisionErro 처리
            if '/' in self.display.text():
                try:
                    result = str(eval(self.display.text()))
                except ZeroDivisionError:
                    result = 'ZeroDivisionError'
                    init.append('clear')
                self.display.setText(result)

            else:
                try:
                    result = str(eval(self.display.text()))
                except:
                    result = 'Error!'
                    init.append('clear')

                self.display.setText(result)

        elif key == 'C':
            self.display.clear()
        elif key == constantList[0]:
            self.display.setText(self.display.text() + '3.141592')
        elif key == constantList[1]:
            self.display.setText(self.display.text() + '3E+8')
        elif key == constantList[2]:
            self.display.setText(self.display.text() + '340')
        elif key == constantList[3]:
            self.display.setText(self.display.text() + '1.5E+8')
        elif key == functionList[0]:
            n = self.display.text()
            value = calcFunctions.factorial(n)
            self.display.setText(str(value))
            init.append('clear')
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        else:
            self.display.setText(self.display.text() + key)  ## 계산 입력
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
            except:
                result = 'Error!'
            self.display.setText(result)
            self.erasecount = 1

        elif key == 'C':
            self.display.clear()
        elif key == constantList[0]:
            self.display.setText('3.141592')
        elif key == constantList[1]:
            self.display.setText('3E+8')
        elif key == constantList[2]:
            self.display.setText('340')
        elif key == constantList[3]:
            self.display.setText('1.5E+8')
        elif key == functionList[0]:
            try:
                n = str(eval(self.display.text()))
                value = calcFunctions.factorial(n)
            except:
                value = 'Error!'
            self.display.setText(str(value))
        elif key == functionList[1]:
            n = self.display.text()
            value = calcFunctions.decToBin(n)
            self.display.setText(str(value))
        elif key == functionList[2]:
            n = self.display.text()
            value = calcFunctions.binToDec(n)
            self.display.setText(str(value))
        elif key == functionList[3]:
            n = self.display.text()
            value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        elif key == additionalconstantList[0]:
            n = self.display.text()
            if n == '': value = 1
            else: value = int(n)
            self.display.setText(str(value))
        elif key == additionalconstantList[1]:
            n = self.display.text()
            if n == '': value = 60
            value = int(n) * 60
            self.display.setText(str(value))
        elif key == additionalconstantList[2]:
            n = self.display.text()
            if n == '': value = 3600
            else: value = int(n) * 3600
            self.display.setText(str(value))
        elif key == additionalconstantList[3]:
            n = self.display.text()
            if n == '': value = 60 * 3600
            else: value = int(n) * 60 * 3600
            self.display.setText(str(value))
        elif key == additionalfunctionList[0]:
            n = self.display.text()
            try:
                a = int(n)
                value = "yes"
                for i in range(2, a):
                    if a % i == 0:
                        value = "no"
                        break
            except:
                value = "Error!"
            self.display.setText(str(value))
            self.erasecount = 1
        elif key == additionalfunctionList[1]:
            n = self.display.text()
            try:
                value = float(n) * float(n)
            except:
                value = "Error!"
            self.display.setText(str(value))
        elif key == additionalfunctionList[2]:
            n = self.display.text()
            try:
                value = oct(int(n))
            except:
                value = "Error!"
            self.display.setText(str(value))
        elif key == additionalfunctionList[3]:
            n = self.display.text()
            try:
                value = hex(int(n))
            except:
                value = "Error!"

            self.display.setText(str(value))
        else:
            if self.erasecount == 1:
                self.erasecount = 0
                self.display.setText('')
            self.display.setText(self.display.text() + key)
    def buttonClicked(self):

        if self.display.text() == 'Error!':
            self.display.setText('')

        button = self.sender()
        key = button.text()

        if key == '=':
            try:
                result = str(eval(self.display.text()))
                self.flag = 1
            except:
                result = 'Error!'
            self.display.setText(result)

        elif key == 'C':
            self.display.clear()
        elif key in constantList:
            self.idx = 0
            self.display.setText(self.display.text() +
                                 self.constantVal[constantList.index(key)])
        elif key in functionList:
            n = str(eval(self.display.text()))
            self.flag = 1
            if functionList.index(key) == 0:
                n = str(eval(self.display.text()))
                value = calcFunctions.factorial(n)
            elif functionList.index(key) == 1:
                value = calcFunctions.decToBin(n)
            elif functionList.index(key) == 2:
                value = calcFunctions.binToDec(n)
            elif functionList.index(key) == 3:
                value = calcFunctions.decToRoman(n)
            self.display.setText(str(value))
        elif key in operatorList:

            # 계산 결과에 괄호 연산자 버튼을 누르면 결과값이 나타나는 오류를 수정
            if self.flag == 1 and key == "(":
                self.display.setText("Error!")
                self.flag = 0
            #괄호가 열려있을 때에만 괄호를 닫을 수 있도록 만들었다.
            elif key == "(":
                self.display.setText(self.display.text() + key)
                self.parIdx = 1
            elif self.parIdx == 1 and key == ")":
                self.display.setText(self.display.text() + key)
                self.parIdx = 0
            elif self.parIdx == 0 and key == ")":
                self.display.setText(self.display.text())
            #나머지의 경우에는 연산이 가능해지도록 한다.
            #연산자가 연속으로 중복되어 입력되는 것을 방지한다.
            else:
                if self.idx == 0:
                    self.idx = 1
                    self.display.setText(self.display.text() + key)
                    self.flag = 0

        #계산이 끝났을 때 연산자가 아닌 숫자 버튼을 누르면, 새로운 수로 시작하지 않고 결과 뒤에 새로운 숫자가 쓰여지는 것을 방지한다.
        elif key in numPadList:
            self.idx = 0
            if self.flag == 1 and key != "=":
                self.display.setText(key)
                self.flag = 0
            #그리고 함수 계산 후에도 결과값 뒤에 새로운 숫자가 쓰여지는 것을 방지한다.
            elif self.flag == 1:
                self.display.setText(key)
                self.flag = 0
            else:
                self.display.setText(self.display.text() + key)
        else:
            self.display.setText(self.display.text() + key)