Question:
1. Write out several branch structures in Python and explain their execution process;
(1) if:
If expression: #条件
Statement #输出
(2) If...else ...
If expression: #条件
Statement #输出
else: #其他条件
Statement #其他输出
(3) If...elif...else ...
If expression: #条件1
Statement #输出1
Elif expression: #条件2
Statement #输出2
Else
Statement #其他输出
2. Write out several loop structures in Python and explain their execution process;
(1) For loop
For I in Range (m.n,x):
The Loop statement #条件
Statement #输出
(2) While loop
While expression (or True,false):
The Loop statement #条件
Statement #输出
(2) while ... else .....
While expression:
Loop Statement #条件1
Statement #输出1
Else
Statement #输出2
3. Do you support switch statements in Python?
If supported, write out the statement format;
If not, say how python can achieve the same functionality;
In Python does not support switch statements, if you want to achieve the effect of switch, is to use if...elif...elif...else ... Statement
Programming Exercises:
1. The user enters a number to determine whether it is prime;
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/03/CC/wKiom1mgL4Dg2HJcAACA8y-h1IM457.png "title=" Screenshot from 2017-08-25 22-08-43.png "alt=" Wkiom1mgl4dg2hjcaaca8y-h1im457.png "/>
2. Write a Python script to determine if the variable name entered by the user is legal?
(The first letter or underscore, the others are numbers, letters or underscores)
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/A2/7C/wKioL1mgM6qDeyUvAABwg-wXDqs647.png "title=" Screenshot from 2017-08-25 22-26-41.png "alt=" Wkiol1mgm6qdeyuvaabwg-wxdqs647.png "/>
Python Exercise 2