title: There are four numbers: 1, 2, 3, 4, how many different and no repetition of the number of three digits? What's the number?
Program Analysis: can be filled in hundreds, 10 digits, single digit numbers are 1, 2, 3, 4. Make all the permutations and then remove the permutations that do not meet the criteria.
Program Source code:
Source:
#!/usr/bin/python
#-*-Coding:utf-8-*-
For I Inch Range(1,5):
For J Inch Range(1,5):
For K Inch Range(1,5):
If( I! = k) and (i! = j) and (j! = k
)
:
print i,J,K
My Source:
Num=5
#num =raw_input ("input number to get Three-digital number:")
List1=range (1,num)
Counter=0
For I in List1:
For J in List1:
if (I!=J):
For K in List1:
if (I!=j and J!=k and i!=k):
Print (I*100+J*10+K)
Counter+=1
Else
Continue
Else
Continue
Print ("Total:" +str (counter))
Other people's solutions refer to:
Use the list form and calculate the summary:
#!/usr/bin/python#-*-Coding:utf-8-*-# The original answer does not indicate the number of three digits, add the number of three digits without repetitionD=[]ForAInchRange(1,5): ForBInchRange(1,5): ForCInchRange(1,5): If (A!=B) and (a!= c) andc!=b D. ([a,bc) print Len (dprint D
Hope
[Email protected]
Combine the For loop and if statement into one sentence and print the result directly
#!/usr/bin/env python#-*-Coding:utf-8-*-List_num= [1,2,3,4]List= [I*100 +J*10 + k for I in List_num for J in List_num for K in list_num
if
(j! = I and K! = j and K! = i)]print c32> (list)
Habit Oolong Tea
[Email protected]
Reference method (set maximum, minimum value):
#!/usr/bin/python#-*-Coding:utf-8-*-Line=[]ForIInchRange(123,433):A=I%10B=(I%100)10C=(I%1000)100IfA!=BandB!=CandA!=Cand 0<A<5 and 0<b<5 and 0< c<5 : print (i line. (i) print ( "The total is: ' ,len (line
Python exercises to print three-bit non-repeating numbers