2019python face questions - 1,2,3,4 figures, the number of other with no repeat can be composed of triple-digit figures

 

1,2,3,4 figures, the number of other with no repeat of the three-digit numbers can be composed? How much are?

 

method one:

 

# Python . 3 

# easiest way Print ([(XYZ)
for X in Range ( . 1 , . 5 ) for Y in Range ( . 1 , . 5 ) for Z in Range ( . 1 , . 5 ) IF ((X! = Y) and ( Y! = Z) and (X! = Z))]) # run results [( 1 , 2 , 3 ), ( 1 , 2 , 4 ), ( 1 , 3 , 2 ), ( 1, 3, 4), (1, 4, 2), (1, 4, 3), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3),
(3, 1, 2), (3, 1, 4), (3, 2, 1), (3, 2, 4), (3, 4, 1), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2)] # 详细步骤
def num_range(): i
= 0 for x in range(1,5): for y in range(1,5): for z in range(1,5): if x != y & y != z & z !=x: i += 1 print('% D% D% D ' % (X, Y, Z), End = ' ' ) Print ( ' Total Results:% s a ' % I) return I # operation results 123,124,132,134,142 143,213,214,231,234 241 243 312 314 321,324,341,342,412 total 413,421,423,431,432 results: 24

 

Method Two:

# Using POP () 

DEF num_pop (N1, N2, N3, N4): 
    n_list = [N1, N2, N3, N4] 
    COUNT = 0 
    for X in Range (len (n_list)): 
        nn_list = n_list.copy () # for each loop must copy a list of 
        A = STR (nn_list.pop (X))
         for Y in Range (len (nn_list)): 
            nnn_list = nn_list.copy () 
            B = STR (nnn_list.pop (Y))
             for Z in Range (len (nnn_list)): 
                Print (A + B + STR (nnn_list [Z]), End = ' ' ) 
                COUNT + = . 1 
    Print ( ' final result:% s a ' % COUNT)
     return n_list 
num_pop ( . 1 , . 3 , . 6 , . 4 ) 

run results: 
136  134  163  164 is  143  146  316  314  361  364  341  346  613  614  631  634  641  643  413  416  431  436  461  463 final result: 24
 
# using remove ()
def num_remove(n1, n2, n3, n4): n_list
= [n1, n2, n3, n4] count = 0 for x in n_list: nn_list = n_list.copy() nn_list.remove(x) a = str(x) for y in nn_list: nnn_list = nn_list.copy() nnn_list.remove(y) b = str(y) for z in nnn_list: print(a+b+str(z),end = ' ') COUNT + = . 1 Print ( ' final result:% s a ' % COUNT) return n_list num_remove ( . 1 , 2 , . 4 , . 5 )

the results:
124,125,142,145,152 154,214,215,241,245 251,254,412,415,421 425 451 452 512 514,521,524,541,542 The end result: 24

 

 View Code

 

Method three:

# Has a minimum of four digits, composed of a random three-digit 
DEF num_remove_many (N1, N2, N3, N4, * args): 
    n_list = [N1, N2, N3, N4]
     for  var  in args: 
        n_list.append ( var ) 
    COUNT = 0 
    for X in n_list: 
        nn_list = n_list.copy () 
        nn_list.remove (X) 
        A = STR (X)
         for Y in nn_list: 
            nnn_list = nn_list.copy () 
            nnn_list.remove (Y) 
            B =STR (Y)
             for Z in nnn_list: 
                Print (A + B + STR (Z), End = '  ' ) 
                COUNT + = . 1 
    Print ( ' final result:% s a ' % COUNT)
     return n_list 
num_remove_many ( . 1 , 2 , 4 , 5 , 3 ) 
        
run results: 
124  125  123  142  145  143  152  154  153  132  134  135  214  215  213 241  245  243  251  254  253  231  234  235  412  415  413  421  425  423  451  452 
453 431 432 435 512 514 513 521 524 523 541 542 543 531 532 534 312 314 315 321 324 325 341 342 345 351 352 354 Final results: 60

 

Guess you like

Origin www.cnblogs.com/yekushi-Z/p/11457739.html