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)