当前位置:网站首页>09 - process control - judgment statement
09 - process control - judgment statement
2022-04-22 05:57:00 【ʕ·͡ˑ· ཻ ʔ**ʕ·͡ˑ· ཻ ʔ】
Catalog
One 、 Process control classification
Two 、 Three processes of program execution
3、 ... and 、 The definition of judgment
Four 、if Judge the basic syntax of a sentence
5、 ... and 、else Judgment statement
6、 ... and 、if-else Illustrate with examples - To determine the age
7、 ... and 、 The combination of judgment statements and logical operators
8、 ... and 、 The judgment statement is illustrated with logical operators
Ten 、elif Examples of multiple judgments
Twelve 、if Examples of nesting
13、 ... and 、 Comprehensive quotation - Rock-paper-scissors
fourteen 、 The treatment of random numbers
One 、 Process control classification
-
Judgment statement :if
-
Loop statement :while loop and for loop
Two 、 Three processes of program execution
3、 ... and 、 The definition of judgment
-
If the conditions are met , To do something .
-
If the conditions are not met , Just do something else , Or do nothing .
-
Be careful : The keywords involved in the judgment statement are if、else、elif.
Four 、if Judge the basic syntax of a sentence
-
You can put the whole if Statement as a complete block of code .
-
The code is indented with a tab key , Or four spaces .
-
stay Python In development ,tab Keys and spaces cannot be mixed .
-
pycharm Can be used directly in tab Key to complete code indentation , Because the default setting will automatically set a tab Key to four spaces .
5、 ... and 、else Judgment statement
-
Used to deal with situations where conditions are not met .
-
if and else Statements and their indented parts together are a complete block of code .
-
else Keywords must be the same as if A combination of , Not to be used alone .
6、 ... and 、if-else Illustrate with examples - To determine the age
-
Define an integer variable to record age .
-
Judge whether it is full 18 year (>=).
-
If full 18 One year old , Allow to enter the Internet bar hi pi .
7、 ... and 、 The combination of judgment statements and logical operators
-
In program development , Usually when judging conditions , Will need Judge multiple conditions at the same time .
-
Only Multiple conditions are met , only Can execute new follow-up code , At this time, we need to make be used Logical operators .
8、 ... and 、 The judgment statement is illustrated with logical operators
-
Define an integer variable age, Write code to determine whether the age is correct .
-
The required person's age is 0~120 Between the ages of .
-
Define two integer variables python_score、c_score Write code to judge performance .
-
It is required that only one score is greater than 60 Points are qualified .
-
Define a boolean variable is_employee, Write code to judge whether it is an employee of the company .
-
If not , Prompt: no entry allowed .
Nine 、elif Multiple judgments
-
Application scenarios : When judging conditions , Multiple criteria are required , And the code to be executed corresponding to the unused conditions .
-
Be careful :elif and else And if A combination of , It can't be used alone .
Ten 、elif Examples of multiple judgments
11、 ... and 、if Nesting of
-
Application scenarios : When the previous conditions are met , Add additional judgment .
-
Be careful : Partially through if Nested variables for judgment , Need to be defined as a local variable .
Twelve 、if Examples of nesting
-
Define Boolean variables has_ticket Indicates whether there is a ticket .
-
Define integer variables knife_length Indicates the length of the knife , Company cm.
-
First, check whether there is a ticket , If there is , To allow security checks .
-
At security check , The length of the knife needs to be checked , Judge whether it exceeds 20cm.
-
If you don't have a ticket, you are not allowed to enter the door .
13、 ... and 、 Comprehensive quotation - Rock-paper-scissors
-
Enter the punch you want from the console ,1: stone 、2: scissors 、3: cloth .
-
The computer punches at random - Let's assume that computers can only make stones , Complete the overall code function .
-
Compare the outcome .
fourteen 、 The treatment of random numbers
-
First step : stay python in , To use random numbers , First, you need to import the module of random numbers ( tool kit ).
-
The second step : call random Module randint Method can generate random numbers .
15、 ... and 、Debug debugging
-
effect : View code execution
-
Operation steps :
-
Be careful :
-
Right click , Choose “Debug' file name '” Run code .
-
Step by step , View the execution process .
版权声明
本文为[ʕ·͡ˑ· ཻ ʔ**ʕ·͡ˑ· ཻ ʔ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220538317058.html
边栏推荐
- Full Permutation (backtracking) template
- codeforces div2 777 A
- Missile interception problem (DP, Dilworth theorem)
- 0/1背包问题(动态规划+动规优化)
- 06-数据类型
- LeetCode 1591. Strange printer II -- judgment sorting
- MYSQL知识点总结大全
- Why introduce collaborative process
- Opencv skeleton extraction / image thinning code
- C language -- classic 100 questions
猜你喜欢

LeetCode 2049. Count the number of nodes with the highest score -- traversal of the tree

蓝桥冲刺专题——BFS

Basic knowledge of software testing

Leetcode 486 Predicting Winners -- dynamic programming + game theory

卷积神经网络

Cytoscape安装教程

蓝桥杯31天冲刺 Day18

蓝桥杯31天冲刺 Day3

LeetCode 467. Dynamic programming -- the only substring in the surrounding string

TCGA database Ensembl ID is transformed into gene symbol to extract the required RNA species expression profile list information
随机推荐
raspberry keras-ocr can‘t allocate memory in static TLS block
蓝桥杯31天冲刺 Day4
layer关闭弹窗,刷新父页面
苹果cms设置本地播放器 ckplayer(版本:ckplayerx)
‘PdfFileWriter‘ object has no attribute ‘stream‘
Imdecode source code interpretation
11 - 流程控制-for循环
Interpretation of imencode source code
链表的逆序输出 C语言三行代码 递归栈
The ECDSA host key for raspberrypi. Local has changed solution
正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是 因为系统
Optimization theory: transportation problem (I) finding the minimum freight [northwest corner method, minimum element method, Vogel method]
软件测试相关基础知识
苹果 CMS 搭建视频网站,定时采集视频
Machine learning -- drawing P-R curve and ROC curve with iris data set
CONDA command
conda命令
ip数据报中首部 总长度 片偏移的单位
蓝桥杯31天冲刺 Day3
Golang learning and school recruitment experience