The simplest sort of built-in functions that directly call the sort ()
function to get x by input (), y, z them into a list of list
then calls list.sort () to sort
. 1 X = INPUT ( ' Enter X: ' ) 2 Y = INPUT ( ' Enter Y: ' ) . 3 Z = INPUT ( ' Enter Z: ' ) . 4 . 5 # List = [] # to define the list to the append () method can use only a list append method, no statement before the interpreter can not determine the type of list, but character 6 # list.append (the X-, the y-, z) #append () method only one parameter 7 list = [X, Y, Z] # directly assigned to the list . 8 Print ( ' sort before: ' , list) . 9 10 the list.sort () # Sort () is built sort function, you can sort character type. The default is ascending 11 Print( ' Ascending order: ' , List) 12 is 13 is the list.sort (reverse = True) # if desired in descending order, the need to pass as a parameter a reverse = True 14 Print ( ' descending: ' , List)
operation result:
A first number: 1 2 second number: 2 3 The third number: 3 . 4 before sorting: [ ' 1 ' , ' 2 ' , ' 3 ' ] 5 Ascending: [ ' 1 ' , ' 2 ' , ' 3 ' ] 6 descending order: [ ' 3 ' , ' 2 ' , ' 1 ' ]