+ 1
How can we see each ine of Python code works?
I mean, do you know, can i see 'What does each line of python code do?', i mean like, a code like this: a = 1 ---> defines new variable and insert it's value print(a) ---> prints out the value of a a = 3 ---> change the value of 'a' variable If you know, thank you so much.
5 Answers
+ 2
thanks
+ 1
i've try the interpreter many months ago, but i just want to know, what does each line of this code do?
def bubble_sort(nlist):
for passnum in range(len(nlist)-1,0,-1):
for j in range(passnum):
if nlist[j]>nlist[j+1]:
nlist[j], nlist[j+1] = nlist[j+1], nlist[j]
nlist = [14,46,43,27,57,41,45,21,70]
bubble_sort(nlist)
print(nlist)
0
you can try a python interpreter
it processes the code as you enter
not exactly what you want but still its interesting check it out
0
def .. -> declaration of function
for passnum .. -> starts from len(nlist)-1 till its 0 and reduce 1 every time
for j .. -> loop from 0 till passnum
nlist[j] .. -> checks if element in j position is greater than next element
nlist[j] .. -> if yes then swap their places
nlist .. -> the list
bub .. -> calling function with nlist as arguement
print (nlist) .. -> prints sorted nlist
0
np :)