程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python basics] loop, termination

編輯:Python

@[TOC] Three process control )

One 、 Sequence flow control

Read in code order

Two 、 Branch process control

1、 General flow chart

2、 Ternary branch
Example 1

Example 2

practice

 Code requirements :
1. The number of user codes and passwords
2. Determine whether the user name and password are correct ( user name =wadmin, password =westos)
3. If correct :“ user admin Login successful ”
4. If not :“ user admin Login failed ”

3、 ... and 、 loop

Example 1 while loop

Example 2 Dead cycle
while ture It means always executing

 The user successfully logged in and entered the system , Login failed , Continue to log in


Example 3 Output numbers from 1 To 100
range function

Example 4 for loop


Example 5 for Loop through the string

Example 6 while and else Combined cycle

Four 、 End cycle

1、break Jump out of all loops

2、debug Step by step debugging

3,continue: End this round ahead of schedule continue All the code after that

5、 ... and 、 Example

1、 Example to find 99 multiplication table
Ideas :
i from 1 To 9
Every j from 1 To i

2、 Check whether the user name and password are respectively admin and westos, If it is correct, successful login will be displayed , An error displays login failure . If it is more than three times, it shows that the login is more than 3 Time , immediate withdrawal .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved