diff --git a/calc.py b/calc.py index ffff18cc923fdfec663adb198a1482137680db71..e7c6b9e4026b2373355f91d2101bb2e8d72a3427 100644 --- a/calc.py +++ b/calc.py @@ -69,7 +69,8 @@ class Calc(QMainWindow): if self.y is not None: #有y self.y =self.y + value else:#无y - self.y = value + if value != '0': + self.y = value self.text_result.setText(self.y) else:#无运算符 @@ -77,21 +78,25 @@ class Calc(QMainWindow): self.x = self.x + value else: - self.x = value + if value != '0': + self.x = value self.text_result.setText(self.x) # 开始处理运算符 # 1.点运算符时记录运算符 + # 2.点运算符时计算结果,然后记录运算符(x,y,oper都有值) # 2.点运算符时记录运算符并计算结果(x,y,oper都有值) # 3.点运算符时记录运算符,并将x置为0(x无值) + elif value in "+-*/": - self.operator = value + if self.x is None: self.x = 0 if self.x and self.y and self.operator: self.calculate() + self.operator = value # 处理点击等号的操作 # 1.点等号时计算结果 (x,y,oper都有值)