Python 100 Cases (001)

Source: Internet
Author: User

1 #!/usr/bin/env python2 #Coding:utf-83 4 " "There are four numbers: 1, 2, 3, 4, how many three digits can be made up of each other without repeating numbers? What's the number? " "5n = 16num = [4, 2, 3, 1]7List_num = [I * + j * + K] forIinchNum forJinchNum forKinchNumif(I! = j) and(j! = k) and(I! =k)]8 Print('a three-digit number that can make up a different, non-repeating number of%s'%Len (list_num))9 Print('They are%s, respectively'%list_num)Ten  One #sort by from small to large A  forIinchxrange (len (list_num)): -      forJinchxrange (len (list_num)): -         ifList_num[i] <List_num[j]: theList_num[i], list_num[j] =List_num[j], List_num[i] - Print('their order from small to large is%s'%list_num) -  - #the sum of all the three-digit numbers that meet the requirements +sum =0 -  forIinchList_num: +sum = sum +I A Print('their cumulative sum is%s'%sum) at  -Sum_0 =0 -Sum_1 =0 - #all even and -  forIinchList_num: -     ifI% 2 = =0: inSum_0 = Sum_0 +I - Print('all even sums are%s'%sum_0) to  + #Find all odd and -  forIinchList_num: the     ifI% 2! =0: *Sum_1 = Sum_1 +I $ Print('all even sums are%s'% sum_1)

Python 100 Cases (001)

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.