Home > other >  Urgent urgent for Python bosses to help you
Urgent urgent for Python bosses to help you

Time:03-19


Program: four number is known, use the if statement, put them in the order from large to small output, use Python, thank you

CodePudding user response:

There is a call what, bubble sort, in order to lower the

CodePudding user response:

To sort, must the if?
 
,77,21,36 numlist=[1]
For I in range (3) :
If numlist [I] & gt; Numlist [I + 1] :
Ii=numlist [I + 1]
Numlist [I + 1)=numlist [I]
Numlist [I]=ii
Print (numlist)

CodePudding user response:

refer to the second floor weixin_45903952 response:
want to sort, if?
 
,77,21,36 numlist=[1]
For I in range (3) :
If numlist [I] & gt; Numlist [I + 1] :
Ii=numlist [I + 1]
Numlist [I + 1)=numlist [I]
Numlist [I]=ii
Print (numlist)

Can use the if

CodePudding user response:

A classic bubble sort

 
A=[4, 34, 5, 12]

For I in range (len - 1) (a) :
For j in range (len (a) - 1 - I) :
If a [j] A [j], a [j + 1)=a [j + 1], a [j]

Print (a)

CodePudding user response:

Have that sort of tools
  • Related