鱼C论坛

 找回密码
 立即注册
查看: 3276|回复: 7

[技术交流] Python:每日一题 113

[复制链接]
发表于 2017-10-16 08:39:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 jerryxjr1220 于 2017-10-16 08:40 编辑

首先我们的玩法做了一下改变:
1. 楼主不再提供答案。
2. 请大家先独立思考”,再参考其他鱼油的解答,这样才有助于自己编程水平的提高。
3. 鼓励大家积极答题,奖励的期限为出题后24小时内。
4. 根据答案的质量给予1~3鱼币的奖励。

如果大家都有跟着@小甲鱼老师的视频好好学习python的话,自己编写数学计算器这种小程序应该都能没有问题了,接下来的几个小练习中,我将一步一步引导大家,如何编写一个矩阵计算器,像这个样子,很激动吧?
Untitled.png
在上一期中我们设计了矩阵乘法,链接地址:http://bbs.fishc.com/thread-97774-1-1.html。这期我们继续来设计矩阵的除法

题目:矩阵除法
矩阵除法的基础知识:
1.PNG 2.PNG 3.PNG 4.PNG 5.PNG 6.PNG

基础篇:
现在给定两个M x M的矩阵(2<=M<=5),请设计程序,输出计算结果,结果同样以矩阵形式输出。

提高篇:
给定一个M x P的矩阵和一个N x P的矩阵(1<=M,N,P<=5且N,M,P 不同时为1),请设计程序,输出计算结果,结果同样以矩阵形式输出。

  1. def matrix_calc(list1, list2):
  2.     'Your code here'
  3.     return result
复制代码



备注:由于矩阵除法计算比较复杂,有能力的鼓励自己写求解程序,觉得困难的可以借助numpy求解,相信还是比较容易的。。

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-10-16 08:59:03 | 显示全部楼层
numpy的矩阵计算还是很方便的,抛砖引玉。
  1. In [13]: A
  2. Out[13]:
  3. array([[1, 2, 3],
  4.        [4, 5, 6],
  5.        [7, 8, 9]])

  6. In [14]: E
  7. Out[14]:
  8. array([[1, 0, 0],
  9.        [0, 1, 0],
  10.        [0, 0, 1]])

  11. In [15]: A_1 = E/A

  12. In [16]: A_1
  13. Out[16]:
  14. array([[ 1.        ,  0.        ,  0.        ],
  15.        [ 0.        ,  0.2       ,  0.        ],
  16.        [ 0.        ,  0.        ,  0.11111111]])

  17. In [17]: B
  18. Out[17]:
  19. array([[9, 8, 7],
  20.        [6, 5, 4],
  21.        [3, 2, 1]])

  22. In [18]: B/A
  23. Out[18]:
  24. array([[ 9.        ,  4.        ,  2.33333333],
  25.        [ 1.5       ,  1.        ,  0.66666667],
  26.        [ 0.42857143,  0.25      ,  0.11111111]])

  27. In [19]: B//A
  28. Out[19]:
  29. array([[9, 4, 2],
  30.        [1, 1, 0],
  31.        [0, 0, 0]], dtype=int32)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-16 14:01:52 | 显示全部楼层
用pyQT5写了一个界面,结合上次做的矩阵相乘。矩阵转置和求模都是针对第一个矩阵
界面的代码在附件中。

  1. # -*- coding: utf-8 -*-

  2. from PyQt5 import QtCore, QtGui, QtWidgets
  3. from PyQt5.QtWidgets import QDialog,QApplication
  4. from PyQt5.QtGui import QIcon
  5. import numpy as np

  6. from ui_MatrixCalculator import Ui_Dialog

  7. def matrix_calc_multiple(list1, list2):

  8.   result_l=[[0 for col in range(len(list1))] for row in range(len(list1))]
  9.   
  10.   #将list2 转置
  11.   list2_t= [[row[i] for row in list2] for i in range(len(list2[0]))]

  12.   indexi=0
  13.   for i in list1:
  14.     indexj=0;
  15.     for j in list2_t:
  16.         result_l[indexi][indexj] = sum([e1 * e2 for (e1,e2) in zip(i,j)])
  17.         indexj=indexj+1
  18.     indexi=indexi+1
  19.   
  20.   return result_l

  21. def matrix_calc_sum(list1, list2):

  22.   result_l=[[0 for col in range(len(list1))] for row in range(len(list1))]
  23.   
  24.   #将list2 转置
  25.   list2_t= [[row[i] for row in list2] for i in range(len(list2[0]))]

  26.   indexi=0
  27.   for i in list1:
  28.     j=list2[indexi]  
  29.     result_l[indexi] = [e1 + e2 for (e1,e2) in zip(i,j)]
  30.     indexi=indexi+1
  31.   
  32.   return result_l


  33. def matrix_calc_sub(list1, list2):

  34.   result_l=[[0 for col in range(len(list1))] for row in range(len(list1))]
  35.   
  36.   #将list2 转置
  37.   list2_t= [[row[i] for row in list2] for i in range(len(list2[0]))]


  38.   indexi=0
  39.   for i in list1:
  40.     j=list2[indexi]  
  41.     result_l[indexi] = [e1 - e2 for (e1,e2) in zip(i,j)]
  42.     indexi=indexi+1
  43.   
  44.   return result_l





  45. class myCalculator(QDialog, Ui_Dialog):
  46.     def __init__(self,parent=None):  
  47.         super(myCalculator,self).__init__(parent)
  48.         self.setupUi(self)

  49.         self.pushButton01.clicked.connect(lambda: self.MaxtrixCal(1))
  50.         self.pushButton02.clicked.connect(lambda: self.MaxtrixCal(2))
  51.         self.pushButton03.clicked.connect(lambda: self.MaxtrixCal(3))
  52.         self.pushButton04.clicked.connect(lambda: self.MaxtrixCal(4))
  53.         self.pushButton05.clicked.connect(lambda: self.MaxtrixCal(5))
  54.         self.pushButton06.clicked.connect(lambda: self.MaxtrixCal(6))

  55.     def MaxtrixCal(self,n):
  56.         mStr=self.plainTextEdit.toPlainText().split('\n')
  57.         a_list=[]
  58.         for i in mStr:
  59.             a_list=a_list+[(eval('['+i+']'))]

  60.         mStr=self.plainTextEdit_2.toPlainText().split('\n')
  61.         b_list=[]
  62.         for i in mStr:
  63.             b_list=b_list+[(eval('['+i+']'))]
  64.         

  65.         np_a=np.array(a_list)
  66.         np_b=np.array(b_list)

  67.         if (n==1):
  68.           np_c=matrix_calc_sum(np_a,np_b)
  69.         elif (n==2):
  70.           np_c=matrix_calc_sub(np_a,np_b)
  71.         elif (n==3):
  72.           np_c=matrix_calc_multiple(np_a,np_b)
  73.         elif (n==4):
  74.           np_c=np_a/np_b  
  75.         elif (n==5):
  76.           np_c=np_a.T                  
  77.         elif (n==6):
  78.           np_c=np.linalg.norm(np_a)
  79.         else:
  80.           self.plainTextEdit_3.setText('something wrong')

  81.         if(n==6):
  82.             o_str=str(np_c)
  83.         elif (n<4):
  84.           list_c=list(map(str,np_c))
  85.           o_str=''
  86.           for i in list_c:
  87.             o_str=o_str+i[1:-1]+'\n'
  88.         else:
  89.           c=np_c.tolist()
  90.           list_c=list(map(str,c))
  91.           o_str=''
  92.           for i in list_c:
  93.             o_str=o_str+i[1:-1]+'\n'
  94.             
  95.         
  96.         self.plainTextEdit_3.setPlainText(o_str)
  97.          
  98.          
  99. if __name__=="__main__":  
  100.     import sys  

  101.     app=QApplication(sys.argv)  
  102.     myshow=myCalculator()  
  103.     myshow.show()  
  104.     sys.exit(app.exec_())
复制代码



附上截图:
Matrix_sum.png

Matrix_div.png

ui_MatrixCalculator.zip (1.01 KB, 下载次数: 1)





点评

我很赞同!: 1.0
我很赞同!: 1
输出的矩阵的小数点可以不用保留那么多位, 输出矩阵的行列对齐看起来更美观。  发表于 2017-10-16 14:12

评分

参与人数 1荣誉 +3 鱼币 +3 贡献 +3 收起 理由
jerryxjr1220 + 3 + 3 + 3 答题奖励

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-16 20:22:27 | 显示全部楼层
挑战不用工具库,手动求解
我没听说过矩阵除法,不过看起来就是 "矩阵乘法" + "逆矩阵"
矩阵乘法上个练习已经做过了,直接拿来用好了
剩下就是逆矩阵,用高斯消元法
  1. def invertible_matrix(A):
  2.     rank = len(A)
  3.     assert {rank - len(i) for i in A} == {0} # 确认是方阵
  4.     E = [[0]*i + [1] + [0]*(rank-1 - i) for i in range(rank)] # rank阶单位矩阵

  5.     for i in range(rank):
  6.         # 行交换直至主元不为0,做不到就是不可逆
  7.         for temp in range(i, rank):
  8.             if A[i][i]: break
  9.             A[i], A[temp] = A[temp], A[i]
  10.             E[i], E[temp] = E[temp], E[i]
  11.         else:
  12.             return "矩阵不可逆!" # 行列式为0
  13.             
  14.         # 主元化为1,增广矩阵做相同变换
  15.         pivot = A[i][i]
  16.         A[i], E[i] = [[a/pivot for a in b] for b in (A[i], E[i])]
  17.         
  18.         # 初等行变换,当列主元位置外化0
  19.         for j in range(rank):
  20.             if j != i:
  21.                 times = A[j][i]
  22.                 A[j],E[j]  = [[a-b*times for a,b in zip(*c)] for c in ((A[j],A[i]),(E[j],E[i]))]
  23.     return E

  24. # 后面接上上一练习写的矩阵乘法
  25. def matrix_calc(list1, list2):
  26.     assert len({len(i) for i in list1}) == len({len(j)for j in list2}) == 1 # 确保矩阵
  27.     assert not any(len(list2) - len(i) for i in list1) # 矩阵1列数 == 矩阵2行数
  28.      
  29.     list2 = [[j[i] for j in list2] for i in range(len(list2[0]))]
  30.     return [[sum(a*b for a,b in zip(i,j)) for j in list2] for i in list1]

  31. if __name__ == "__main__":
  32.     B = [[-4,3,0],[3,0,1],[1,2,-2]]
  33.     A = [[1,2,-1],[3,1,0],[-1,0,-2]]
  34.     print(matrix_calc(B, invertible_matrix(A)))
复制代码

评分

参与人数 1荣誉 +3 鱼币 +3 贡献 +3 收起 理由
jerryxjr1220 + 3 + 3 + 3 答题奖励!

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-16 20:27:18 | 显示全部楼层
楼主,你给的例子有误啊
一开始 B = [[-4, 3, 0], [3, 0, -1], [1, 2, -2]]
后面变成 B = [[-4, 3, 0], [3, 0, 1], [1, 2, -2]]
B[1][2] 从-1 变成 1 了,我说算不对····

点评

我很赞同!: 5.0
我很赞同!: 5
我都还没注意,我是从百度百科上复制过来的图片,果然是图片就错了。  发表于 2017-10-17 13:21
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-23 17:02:35 | 显示全部楼层
本帖最后由 qwc3000 于 2017-10-23 17:04 编辑

from he import Ui_Form
from PyQt5 import QtWidgets , QtCore
import  re
import sys
import copy
class mywindow(QtWidgets.QMainWindow):
    def __init__(self,parent=None):
        QtWidgets.QWidget.__init__(self,parent)
        self.ui=Ui_Form()
        self.ui.setupUi(self)
    # 加法
    def hello(self):
        # self.ui.textEdit_A.setText("hello")
        # 获取A B的文本框的相关信息列表
        self.tmpA = self.charsplit(self.ui.textEdit_A.toPlainText())
        self.tmpB = self.charsplit(self.ui.textEdit_B.toPlainText())
        # 先输入要相加的两个矩阵,大小必须一致为mxn,一般矩阵加法才有定义;
        # 所以需要首先判断A B 矩阵的行列数是否相同
        # 相同 继续  不相同跳出
        self.L_A_mn = self.tmpA.pop()
        self.L_B_mn = self.tmpB.pop()
        if self.L_B_mn[0] != self.L_A_mn[0] or self.L_A_mn[1] != self.L_B_mn[1]:
            return
        print("L_A:", self.tmpA)
        print("L_B:", self.tmpB)
        # 定义几个中间转换用变量
        L_tmp_a=[]
        L_tmp_b=[]
        int_tmp_d = 0
        cha_tmp_c = ""
        # a = [1, 2, 3]
        # b = [4, 5, 6]
        # c = [a + b for i in range(min(len(a), len(b)))]
        # a=[self.tmpA + self.tmpB for i in range(min(len(self.tmpA), len(self.tmpB)))]
        # 矩阵加法计算
        for i in range(self.L_A_mn[0]):
            for j in range(self.L_A_mn[1]):
                int_tmp_d = self.tmpA[j]+self.tmpB[j]
                print(int_tmp_d)
                L_tmp_a.append(str(int_tmp_d))
            L_tmp_b.append(L_tmp_a)
            L_tmp_a=[]
        # print(L_tmp_b)
        # 矩阵转换
        for i in range(self.L_A_mn[0]):
            cha_tmp_c += ",".join(L_tmp_b)
            cha_tmp_c += "\n"
        self.ui.textEdit_C.setText(cha_tmp_c)
    # 减法
    def sub(self):
        # self.ui.textEdit_A.setText("hello")
        # 获取A B的文本框的相关信息列表
        self.tmpA = self.charsplit(self.ui.textEdit_A.toPlainText())
        self.tmpB = self.charsplit(self.ui.textEdit_B.toPlainText())
        # 先输入要相加的两个矩阵,大小必须一致为mxn,一般矩阵加法才有定义;
        # 所以需要首先判断A B 矩阵的行列数是否相同
        # 相同 继续  不相同跳出
        self.L_A_mn = self.tmpA.pop()
        self.L_B_mn = self.tmpB.pop()
        if self.L_B_mn[0] != self.L_A_mn[0] or self.L_A_mn[1] != self.L_B_mn[1]:
            return
        print("L_A:", self.tmpA)
        print("L_B:", self.tmpB)
        # 定义几个中间转换用变量
        L_tmp_a = []
        L_tmp_b = []
        int_tmp_d = 0
        cha_tmp_c = ""
        # 矩阵减法计算
        for i in range(self.L_A_mn[0]):
            for j in range(self.L_A_mn[1]):
                int_tmp_d = self.tmpA[j] - self.tmpB[j]
                print(int_tmp_d)
                L_tmp_a.append(str(int_tmp_d))
            L_tmp_b.append(L_tmp_a)
            L_tmp_a = []
        # print(L_tmp_b)
        # 矩阵转换
        for i in range(self.L_A_mn[0]):
            cha_tmp_c += ",".join(L_tmp_b)
            cha_tmp_c += "\n"
        self.ui.textEdit_C.setText(cha_tmp_c)
    def mult(self):
        # 获取A B 矩阵信息
        self.tmpA = self.charsplit(self.ui.textEdit_A.toPlainText())
        self.tmpB = self.charsplit(self.ui.textEdit_B.toPlainText())
        # 乘法运算
        self.Str_AB = self.Matrix_operator(self.tmpA,self.tmpB)
        # 赋值显示
        self.ui.textEdit_C.setText(self.Str_AB)
    # 除法
    def div(self):
        self.tmpA = self.charsplit(self.ui.textEdit_A.toPlainText())
        self.tmpB = self.charsplit(self.ui.textEdit_B.toPlainText())
        result=self.Matrix_division(self.tmpA,self.tmpB)
        self.ui.textEdit_C.setText(result)
    # 矩阵乘法
    def Matrix_operator(self, L_A, L_B):
        # 处理矩阵信息
        # 使用pop 弹出 L_A的最后一个元素 将弹出的元素赋值给L_A_mn
        # 此L_A_mn元素为A矩阵的mn行列数,同时得到L_A的矩阵列表内容
        self.L_A_mn = L_A.pop()
        self.L_B_mn = L_B.pop()
        # print("abc")
        # 判断AB矩阵是否满足 A为m*p的矩阵,B为p*n的矩阵
        if self.L_A_mn[1] != self.L_B_mn[0]:
            return None
        # 满足继续
        # 取A的第i行
        # 定义一个m*n的列表
        # print("self.L_B_mn[1]) ", self.L_B_mn[1])
        L_AB=[[] for i in range(self.L_A_mn[0])]
        print("L_AB ", L_AB)
        tmp=0
        # 取A的第i行
        for i in range(self.L_A_mn[0]):
            # 取B的j列
            for j in range(self.L_B_mn[1]):
                # 分别取a的ik元素  和 b的kj元素 做乘法 再求和
                for k in range(self.L_B_mn[0]):
                    tmp += L_A[k]*L_B[k][j]
                    print(tmp)
                # 将tmp赋值给AB的ij元素
                L_AB.append(str(tmp))
        # 定义一个字符串 返回使用
        Str_AB=""
        # 将ab列表转为字符串
        for i in range(len(L_AB)):
            Str_AB += ",".join(L_AB)
            Str_AB += "\n"
        # 返回
        return Str_AB
    # 文本拆分
    def charsplit(self, text):
        tmp_mn = []
        tmp=[]
        m = 1
        n = 0
        # 将文本输入框的内容 按照行分成m个元素的列表
        tmp_m = text.split("\n")
        # 获取矩阵有多少行 m行
        m = len(tmp_m)
        # 将m交给mn列表,后面使用
        tmp_mn.append(m)
        # 创建tmp_Ultimate(终极)多维数组
        tmp_Ultimate = [[] for i in range(m)]
        # 将mn列表中的每一个元素分解成n个元素的列表
        for i in range(0, m):
            # 获取m列表的
            tmp_n = tmp_m.split(",")
            n = len(tmp_n)
            # 将n列表中的所有字符串转变为数字
            for j in range(0, n):
                tmp.append(int(tmp_n[j]))
            # 清空
            tmp_n.clear()
            # 赋值给n列表
            # 切片赋值
            # tmp_n=tmp[:]
            # 深度复制
            tmp_n = copy.deepcopy(tmp)
            # print("tmp_n", tmp_n)
            # 清空
            tmp.clear()
            # print("tmp_n b", tmp_n)
            # 赋值给m列表的i组
            tmp_Ultimate += tmp_n
            # 清空
            tmp_n.clear()
        # print("biaozhi ", tmp,tmp1,tmp2)
        # 将m交给mn列表,后面使用
        tmp_mn.append(n)
        tmp_Ultimate.append(tmp_mn)
        # 返回终极列表,此列表包括矩阵的行列元素以及行列数
        return tmp_Ultimate
    # 逆矩阵判断
    def is_Inverse_Matrix(self,L_A):
        a=1
        # 如果不是n阶矩阵,则无逆矩阵
        if len(L_A) == len(L_A[0]):
            determinant = self.Triangle_determinant(L_A)
            for i in range(len(L_A)):
                a = a*determinant
            if a!=0:
                return True
        return False
    # 形成E阵
    # Le参数为矩阵的阶数列表
    def E_matrix(self,L_e):
        # 1、增加E阵
        a = 0
        L_E = [[] for i in range(L_e[0])]
        for i in range(L_e[0]):
            for j in range(L_e[1]):
                if j == a:
                    L_E.append(1)
                else:
                    L_E.append(0)
            a = a + 1
        print(L_E)
        return L_E
    # 三角行列式计算
    def Triangle_determinant(self,L_A):
        # 将行列式的某一行(列)乘以倍数,加到另一行,其行列式等于原行列式
        # 三角行列式等主线上的成绩
        # L_A = self.Matrix_decomposition(L_A, 0)
        determinant = copy.deepcopy(L_A)
        determinant_tmp = copy.deepcopy(L_A)
        a = len(determinant)
        for k in range(len(L_A)):
            for i in range(1 + k, a):
                b = determinant[k] / determinant[k][k]
                for j in range(k, a):
                    c = determinant[j] - determinant[k][j] * b
                    determinant_tmp[j] = c
            determinant = determinant_tmp
        return determinant
    # 逆矩阵计算
    def Inverse_matrix(self,L_A,L_E):
        # 无逆矩阵返回
        print("LA go",L_A)
        if self.is_Inverse_Matrix(L_A)==False:
            print("无逆矩阵")
            return
        L_tmp_a=len(L_A)
        a=1
        # 项目数
        for k in range(L_tmp_a):
            # 第一步将矩阵(0,0)项变为1,同时其E矩阵也除以相应的倍数
            for i in range(len(L_A[0])):
                if i==0:
                    a=L_A[k][k]
                L_A[k]=L_A[k]/a
                L_E[k] = L_E[k] / a
            # 第二步将(0,0)以外的第0列的其他项变为0
            for i in range(0,len(L_A)):
                if i!=k:
                    # 计算倍数
                    multiple=L_A[k]/L_A[k][k]
                    print("hang",i,"lie",k,"beishu",L_A[k],L_A[k][k],multiple)
                    # mn号元素=mn号元素减去 (m-1)n元素乘以倍数
                    # 让mn号元素变为1
                    for j in range(len(L_A[1])):
                        L_A[j] = L_A[j]-L_A[k][j]*multiple
                        L_E[j] = L_E[j]-L_E[k][j]*multiple
        print("E-matrix:",L_E)
        return L_E

    # 除法
    def Matrix_division(self, L_A, L_B):
        # 需要将除数B转变逆矩阵
        # 首先需要判断B是否有逆变矩阵,其充要条件是 B的行列式不为
        L_Result=""
        if self.is_Inverse_Matrix(L_B):
            return
        else:
            # 1、增加E阵
            L_A.pop()
            L_E=self.E_matrix(L_B.pop())
            # 2、计算逆矩阵
            L_N_B=self.Inverse_matrix(L_B,L_E)
            # 3、计算LA和LB逆矩阵的乘法
            L_mn=[]
            L_mn.append(len(L_A))
            L_mn.append(len(L_A[0]))
            L_A.append(L_mn)
            L_mn.append(len(L_N_B))
            L_mn.append(len(L_N_B[0]))
            L_N_B.append(L_mn)
            L_Result=self.Matrix_operator(L_A , L_N_B)
        return L_Result


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    myapp = mywindow()
    myapp.show()
    sys.exit(app.exec_())
##++++++++++++++++++++++++++++++++++##
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'he.ui'
#
# Created by: PyQt5 UI code generator 5.8.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(400, 243)
        self.Button_add = QtWidgets.QPushButton(Form)
        self.Button_add.setGeometry(QtCore.QRect(310, 30, 51, 41))
        self.Button_add.setObjectName("Button_add")
        self.Button_sub = QtWidgets.QPushButton(Form)
        self.Button_sub.setGeometry(QtCore.QRect(310, 80, 51, 41))
        self.Button_sub.setObjectName("Button_sub")
        self.Button_multi = QtWidgets.QPushButton(Form)
        self.Button_multi.setGeometry(QtCore.QRect(310, 130, 51, 41))
        self.Button_multi.setObjectName("Button_multi")
        self.Button_divi = QtWidgets.QPushButton(Form)
        self.Button_divi.setGeometry(QtCore.QRect(310, 180, 51, 41))
        self.Button_divi.setObjectName("Button_divi")
        self.textEdit_A = QtWidgets.QTextEdit(Form)
        self.textEdit_A.setGeometry(QtCore.QRect(20, 40, 104, 71))
        self.textEdit_A.setObjectName("textEdit_A")
        self.textEdit_B = QtWidgets.QTextEdit(Form)
        self.textEdit_B.setGeometry(QtCore.QRect(170, 40, 104, 71))
        self.textEdit_B.setObjectName("textEdit_B")
        self.textEdit_C = QtWidgets.QTextEdit(Form)
        self.textEdit_C.setGeometry(QtCore.QRect(20, 140, 104, 71))
        self.textEdit_C.setObjectName("textEdit_C")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(20, 6, 61, 21))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(10)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(170, 0, 61, 31))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(10)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(Form)
        self.label_3.setGeometry(QtCore.QRect(30, 110, 61, 31))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(10)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")

        self.retranslateUi(Form)
        # 加
        self.Button_add.clicked.connect(Form.hello)
        # 减
        self.Button_sub.clicked.connect(Form.sub)
        # 乘法
        self.Button_multi.clicked.connect(Form.mult)
        # 除法
        self.Button_divi.clicked.connect(Form.div)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.Button_add.setText(_translate("Form", "+"))
        self.Button_sub.setText(_translate("Form", "-"))
        self.Button_multi.setText(_translate("Form", "*"))
        self.Button_divi.setText(_translate("Form", "/"))
        self.label.setText(_translate("Form", "A1"))
        self.label_2.setText(_translate("Form", "B2"))
        self.label_3.setText(_translate("Form", "C3"))

“”“”“”“”“”“”“”“”“”“”“”“”“
参数命名比较混乱,嘿嘿额嘿嘿  2阶除法不好使  
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 19:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表