(i) Python simple application

Source: Internet
Author: User

After self-study, the paper solves several simple problems by using cyclic statements and judgment statements:

1, the realization of 1 to 10 and:

x = 1he = 0while x < one:    if x = = 7:        pass    else:        he = he + x    x = x + 1print (HE)

2, the realization of 1 to 100 and:

X=1he =0while x< 101:    he=x+he    x=x+1print (He)

3, achieve 100 even add:

x = 1while x < 101:    if x% 2 = = 0:        print (x)    else:        pass    x = x + 1

4, achieve the odd sum within 100:

x = 1while x < 101:    if x% 2 = = 0:        pass    else:        print (x)    x = x + 1

5, the realization of seeking 1-2+3-4+5 ... 99 of all numbers of the and:

x = 1he = 00while x <:    if x% 2 = = 0:        he = He-x    else:        he = he + x    x = x + 1print (HE)

6. Achieve three landing attempts:

Pure If statement version:

Idcard = 123passward = 123x = 0a = input ("Please enter your account") c = input ("Please enter your password") if a = = Idcard and c = = Passward:    print ("Login Successful") else:    print ("Login failed")    a = input ("Please enter your account")    c = input ("Please enter your password")    if a = = Idcard and c = = Passward:        prin T ("login successfully")    else:        print ("Login failed")        a = input ("Please enter your account")        c = input ("Please enter your password")        if a = = Idcard and c = = Passward:            print ("Successful login")        else:            print ("Three login failed, forced exit")

To add a while loop version:

idcared= 123passward = 123x = 0while x < 3:    a = input ("Please enter your account")    c = input ("Please enter your password")    if a = = Idcard and C = = Passward:        print ("login successfully")    else:        print ("Login failed Please reenter")        if x==2:            print ("Input three times failed, force exit")        x = x + 1

  

A simple attempt to pass through these questions summarizes 1, often forgetting to add a loop-limiting variable. 2, do not pay attention to the amount of indentation in the code.

(i) Python simple application

Related Article

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.