[2] Just learned some simple exercises for Python and several exercises for python

Source: Internet
Author: User

[2] Just learned some simple exercises for Python and several exercises for python

 

Python dating entertainment club: 613176398

 

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

2. Calculate the sum of all numbers from 1

3. Output all odd numbers in 1-100

4. Output all the even numbers in 1-100

5. Calculate the sum of all numbers of 1-2 + 3-4 + 5... 99.

6. User Login (three chances to try again)

 

 

Question 1:

a = 0while a < 10:    a +=1        if a == 7:        continue    print(a)

Question 2:

Method 1:

a = 0b = 1while b <= 100:    a = a + b    b += 1print(a)

Method 2:

a = 0for i in range(101):        a = a + i        print(a)

Question 3:

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

Question 4:

Method 1:

a = 0while a <= 100:    a += 1    if(a%2) == 0:        print(a-2+1)

Method 2:

a = 0while a <= 99:    a += 1    if(a%2) != 0:        print(a)

Question 5:

a = 0b = 0while a < 99:   a += 1   if a%2 == 1:      b += a   else:      b -= aprint(b)

Question 6:

A = 0 while a <3: name = input ("Enter the User name:") password = input ("enter the password :") a + = 1 if name = 'wxd 'and password = '000000': print ("Login successful") exit () else: print ("input error, enter ") print (" three input errors, exit ") again ")

 

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.