Home > other >  A Python program
A Python program

Time:09-23

Any input three Numbers 0 to 9, the output of all the number and the number of (using the Python language)

Such as: input 1, 2, 3
Output: 123 132 213 231 312 321
6

CodePudding user response:

https://www.cnblogs.com/aiguiling/p/8594023.html
Permutation and combination
The import itertools
For I in itertools. Product (' 123 ', repeat=3) :
Print (I)
Print ()
For I in itertools.com binations (' 123 ', (3) :
Print (I)
Print ()
For I in itertools. Permutations (' 123 ', (3) :
print(i)

CodePudding user response:

For I in itertools. Permutations ([' 1 ', '2', '3'], (3) :
Print (I)

With a list. Append (input data)
Can also be

CodePudding user response:

 def main () : 
Num_1=input (" please enter a number: ")
Num_2=input (" please enter a number: ")
Num_3=input (" please enter a number: ")
Num=list ()
Num_print=list ()
If num_1. Isdigit () and num_2. Isdigit () and num_3. Isdigit () :
If 0 & lt;=int (num_1) & lt;=0 and 9 & lt;=int (num_2) & lt;=0 and 9 & lt;=int (num_3) & lt;=9:
If the int (num_1)!=int (num_2) and int (num_3)!=int (num_2) :
Num1=int (num_1 + num_2 + num_3)
Num2=int (num_1 + num_3 + num_2)
Num3=int (num_2 + num_1 + num_3)
Num4=int (num_2 + num_3 + num_1)
Num5=int (num_3 + num_1 + num_2)
Num6=int (num_3 + num_2 + num_1)
Print (" digital combination is: {}, {}, {}, {}, {}, {}/a total of six ". The format (num1, num2, num3, num4 num5, num6))
The else:
Num. Append (int (num_1 + + num_3 num_2))
Num. Append (int (num_1 + + num_2 num_3))
Num. Append (int (num_2 + + num_3 num_1))
Num. Append (int (num_2 + + num_1 num_3))
Num. Append (int (num_3 + + num_2 num_1))
Num. Append (int (num_3 + + num_1 num_2))
For I in num:
If I not in num_print:
Num_print. Append (I)
Print (" digital combination for: aggregate is {} {}/". The format (num_print, len (num_print)))
The else:
Print (" input error is detected, the number is not in "between 0 ~ 9)
Return to the main ()
The else:
Print (" input error, detect illegal character input!" )
Return to the main ()

If __name__=="__main__ ':
The main ()

This code is not optimal

CodePudding user response:

The
reference 3 floor MuSa xiaoxiang reply:
 def main () : 
Num_1=input (" please enter a number: ")
Num_2=input (" please enter a number: ")
Num_3=input (" please enter a number: ")
Num=list ()
Num_print=list ()
If num_1. Isdigit () and num_2. Isdigit () and num_3. Isdigit () :
If 0 & lt;=int (num_1) & lt;=0 and 9 & lt;=int (num_2) & lt;=0 and 9 & lt;=int (num_3) & lt;=9:
If the int (num_1)!=int (num_2) and int (num_3)!=int (num_2) :
Num1=int (num_1 + num_2 + num_3)
Num2=int (num_1 + num_3 + num_2)
Num3=int (num_2 + num_1 + num_3)
Num4=int (num_2 + num_3 + num_1)
Num5=int (num_3 + num_1 + num_2)
Num6=int (num_3 + num_2 + num_1)
Print (" digital combination is: {}, {}, {}, {}, {}, {}/a total of six ". The format (num1, num2, num3, num4 num5, num6))
The else:
Num. Append (int (num_1 + + num_3 num_2))
Num. Append (int (num_1 + + num_2 num_3))
Num. Append (int (num_2 + + num_3 num_1))
Num. Append (int (num_2 + + num_1 num_3))
Num. Append (int (num_3 + + num_2 num_1))
Num. Append (int (num_3 + + num_1 num_2))
For I in num:
If I not in num_print:
Num_print. Append (I)
Print (" digital combination for: aggregate is {} {}/". The format (num_print, len (num_print)))
The else:
Print (" input error is detected, the number is not in "between 0 ~ 9)
Return to the main ()
The else:
Print (" input error, detect illegal character input!" )
Return to the main ()

If __name__=="__main__ ':
The main ()

This code is not optimal

  • Related