Python stage review-part 1-python Basics Exercises

Source: Internet
Author: User

1, the realization of 1-100 of all and
# method 1:sum = 0 for I in range (1,101):     sum + = i print (sum)  # method 2:num1 = Int (input (' Enter starting number ')) num2 = Int (input (' please lose ) sum = (NUM1 + num2) * NUM2/2 print (int (sum))
2, achieve 1-500 of all odd and
sum = 0for i in range (1,501):     _,result = Divmod (i,2)     If not result:         sum + = i print (sum)
3, the realization of 1!+2!+3!+4!... +20! results
sum = 0result = 0for i in range (1,21):    If i = = 1:        sum = i    else: for J in        Range (1,i+1):            if j = = 1:
   
    result = 1            else:                result *= J    sum + = resultprint (sum)
   
4. Sort the specified list [2,32,43,453,54,6,576,5,7,6,8,78,7,89]
# sorted () copy sort li = [2,32,43,453,54,6,576,5,7,6,8,78,7,89]new_li= sorted (LI) print (LI)  # original list invariant print (New_li) # sort ( ) is in situ sort li = [2,32,43,453,54,6,576,5,7,6,8,78,7,89]li.sort () print (LI)  # Modify the original list directly

  

Python stage review-part 1-python Basics Exercises

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.