How does this programme works?? can anyone explain in detail plz!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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()

2nd Jul 2017, 4:47 PM
Paavan Gupta
Paavan Gupta - avatar
4 Answers
+ 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.
4th Jul 2017, 1:47 PM
Nanda Balakrishnan
+ 2
understood right
4th Jul 2017, 2:55 PM
Nanda Balakrishnan
0
ok, thank you, brother. for helping me 👍
4th Jul 2017, 2:37 PM
Paavan Gupta
Paavan Gupta - avatar
0
yes yes, got it👍
4th Jul 2017, 2:56 PM
Paavan Gupta
Paavan Gupta - avatar