The path to PYTHON's automated learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.