One, user interaction small Program
' GYC ' 'gyc'= input ("What are youname?:" = input ("mima:")print(u,p)
Second, if...else process judgment
#!/usr/bin/env python3.5#*-* coding:utf-8 *-*GYC= 18 Age= Int (Input ("Please enter the age of GYC:"))ifAge = = 18: #判断用户输入的值是否与初始值匹配Print("very good!")Else: #否则, Error! Print("I'm sorry, you're not gyc!. ")Three, while Loop example
GYC = 18NUB=0 whileTrue:#the loop condition is trueNUB + = 1ifNUB = = 3: Print("End") Break Age= Int (Input ("Please enter the age of GYC:")) ifAge = = 18: Print("very good!") Else: Print("I'm sorry, you're not gyc!. ")
Equivalent to the following program
1. Optimize while loop code
#!/usr/bin/env python3.5#*-* coding:utf-8 *-*GYC= 18NUB=0 whileNUB <= 3: Nub+=1 Age= Int (Input ("Please enter the age of GYC:")) ifAge = = 18: Print("very good!") Else: Print("I'm sorry, you're not gyc!. ")Iv. Break and Continue
Break action to end the current loop
Sample Code,
GYC = ('I Love You') Nub=0 whileNUB < 4: Nub+ = 1g= Input ("Please input I love you in English:") ifG = =GYC:Print("I Love You Me too!") Break #当然输入的与初始化的匹配, end the loop, do not go down Else: Print("Please input I love you")Continue
Jump out of the current loop
Sample Code,
for in range: if i% 2 = = 0: continue #当 I divisible 2 o'clock jump out of the current loop to perform the next condition
Print(i)
Output is 1 3 5 7 9
The path to PYTHON's automated learning