Python Language Learning System 7: conditional statement

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qingwufeiyang12346/article/details/102534464

Engaged in embedded systems software and hardware design work we have to do 20 years, during a hardware target board debugging, often require PC software support. During PC software program design, too VB, VB.net and C ++ and other languages, Python found by chance, after exposure, it immediately felt strong, and now my only PC software programming with Python . This series of tutorials from the perspective of hardware-based PC software designed to proceed, the system introduces the Python language, I hope the reader through this tutorial series, can immediately apply their knowledge of the Python language, to really apply the knowledge to the project practice.

Development Environment: Visual Studio Code

Operating System: Microsoft Window 7

Python Version: 3.7

Reference materials: Python quick introductory programming, programmers dark horse, the People's Posts and Telecommunications Press, September 2017 First Edition

Note: The tutorial is only for beginners, experts please bypass
 

A digital input determination is positive, zero, or negative

1, PyQt interface design:

2, object naming:

3, source:

# 系统包
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
# 项目包
from Ui_MainWindow import Ui_MainWindow
 
class CMainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent = None):
        super(CMainWindow, self).__init__(parent)
        self.setupUi(self)
 
        # 主窗体设置
        self.show()

    def Judge(self):
        a = int(self.txtNumber.text())
        if a >= 0:
            if a == 0:
                self.labResult.setText("结果:你输入的数字是0")
            else:
                self.labResult.setText("结果:你输入的数字是正数")
        else:
            self.labResult.setText("结果:你输入的数字是负数")

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = CMainWindow()
    sys.exit(app.exec_())

4. Note:

(1) in the general form of Python if statement is as follows:

if condition_1:
    statement_block_1
elif condition_2:
    statement_block_2
else:
    statement_block_3

(2) To the back of each condition colon: it indicates the following condition is satisfied after the statement block to be executed.

(3) using indentation divided statement blocks, the number of statements in the same indentation together to form a block.

(4) there is no switch in Python - case statement.

5. Exercise:

Write a program conversion dog's age corresponds to the person's age, the algorithm: 0-year-old dog = "less than 14 years of age; 1 year old dog =" 14 years of age; 2-year-old dog = "22 years old; 2 years old dog conversion formula of human = 22 + (age -2) * 5.

Second, find the maximum number of three-digit

1, PyQt interface design:

2, object naming:

3, source:

# 系统包
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
# 项目包
from Ui_MainWindow import Ui_MainWindow
 
class CMainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent = None):
        super(CMainWindow, self).__init__(parent)
        self.setupUi(self)
 
        # 主窗体设置
        self.show()

    def Max(self):
        a = int(self.txtNumber1.text())
        b = int(self.txtNumber2.text())
        c = int(self.txtNumber3.text())
        max = a
        if max < b:
            max = b
        if max < c:
            max = c
        self.txtMaxNumber.setText(str(max))


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = CMainWindow()
    sys.exit(app.exec_())

4. Exercise

Write a program, find the maximum number of four numbers.

 

任何问题,只需在此文章的评论处留言即可,我将尽力解答,不要试图采用其它的联系方式,我一概不理会。

原创性文章,转载请注明出处CSDN:http://blog.csdn.net/qingwufeiyang12346。

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qingwufeiyang12346/article/details/102534464