Python Introductory Exercises

Source: Internet
Author: User

1. Use while loop input 1 2 3 4 5 6 8 9 10

Code:

0  While I <:    1    if7:        continue      Print (i)

Results:

2. For all numbers of 1-100

Code:

i = 0sum = 0while i<=100:i+=1sum = sum+iprint (sum)

Results:

3. All odd numbers in output 1-10:

i = 0while I < 9:i + = 1if I% 2 = = 1:print (i)

Results:

4. All even numbers in the output 1-100

0  while  One :     1    if 2 0 :        print (i)

Results:

5, Beg 1-2+3-4+5 ... 99 of all numbers of the and

i =0J_sum=0O_sum=0sum=0 whileI < About: I+=1    ifI2==1: J_sum= J_sum +IifI2==0: O_sum= O_sum +I sum=j_sum-o_sumprint (j_sum) print (o_sum) print (sum)

Results:

6. User Login (three chance retry)

A = 0while a < 3:a +=1username = input ("Please enter your user name:") Password = input ("Please enter your password:") if username = = ' Wang ': if password = = ' n An ':p rint ("Login succeeded") Breakelse:print ("Login Failed") else:print ("Rewrite input")

Results:

#输入错误:

#输入成功:

Python Introductory Exercises

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.