Python basic job Exercise-20171214

Source: Internet
Author: User

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

 while Count <=:    if count = = 7:        = count + 1        continue    Print (count)     = Count + 1

2. For all numbers of 1-100

Count = 1 sum = 0while count <= 100:sum = sum + countcount = count + 1 print (sum)

3. All odd numbers in output 1-100

Count = 1 while Count <= 100:if count% 2 ==1:print (count) Count = count + 1count = count + 1

4. All even numbers in output 1-100

Count = 1while count <= 100:if count% 2 ==0:print (count) Count = count + 1count = count + 1

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

Count = 1 sum = 0 while Count <= 99:if count ==1:sum = Countcount = Count + 1continueelse:if count% 2 ==1:sum = sum + Countcount = count + 1else:sum = Sum-countcount = count + 1print (sum)

6. User Login (three chance retry)

Count = 1sum = 0while count <= 3:username = input (' Please enter user name: ') password = input (' Please enter user password: ') if username = = ' Jason ' and pass Word = = ' 123 ':p rint (' login successful, welcome ' Jason ' Back! ') Breakelse:sum = 3-countprint (' Username or password error, please re-enter, currently remaining ' +str (sum) + ' opportunity! ') Count = count + 1

 

Python basic job Exercise -20171214

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.