0
How does this programme works?? can anyone explain in detail plz!!
import random import math numList = [] for i in range(5): numList.append(random.randrange(1, 9)) i = len(numList) - 1 while i > 1: j = 0 while j < i: # Tracks the comparison of index values print("\nIs {} > {}".format(numList[j], numList[j+1])) print() # If the value on the left is bigger switch values if numList[j] > numList[j+1]: print("Switch") temp = numList[j] numList[j] = numList[j + 1] numList[j + 1] = temp else: print("Don't Switch") j += 1 print("END OF ROUND") i -= 1 for k in numList: print(k, end=", ") print()
4 Antworten
+ 2
hi bro,
This program will sort the list in ascending order.
first it will create list of 5 random numbers between 1 and 9.
then it will check whether the left hand side has biggest number than right if it so then it will perform swap operation otherwise no swap.
finally it will print the list in ascending order.
+ 2
understood right
0
ok, thank you, brother. for helping me 👍
0
yes yes, got it👍