My subroutine won't call within a for and if...is this normal?

Joined
Jan 25, 2022
Messages
1
Reaction score
0
So here's my code.

def bubblesort(list):
global step
global oldlist
print("""
ORIGINAL LIST""")
print(list)
for i in range(len(list)):
for j in range(len(list)-1):
if float(list[j])>float(list[j+1]):
list[j], list[j+1] = list[j+1], list[j]
if oldlist==list:
end(list)

else:
oldlist=list
step=step+1
print("""
STEP""",step)
print(list)
end(list)

def end(list):
global step
step=step+1
print("""
STEP""",step)
print(list)

step=0
oldlist=[]
list=[]
number=int(input("How many numbers do you want to input to sort? : "))
for i in range(1,number+1):
value=float(input("INPUT NUMBER : "))
list.append(value)
bubblesort(list)

The issue is the bit of code which I have made red and bold. It simply won't call the subroutine when I ask it to. I know it definitely runs through the if since if i put a "print" or "break" in they both work it just won't jump to a sub-routine. Furthermore, the time I call that subroutine later on in the code works and does go to the subroutine. So i'm a bit lost as to what I've done wrong here. Any help?
 
Joined
Mar 3, 2021
Messages
241
Reaction score
30
Had to guess on some of the indentation, but it seems to be working to me. What output are you seeing that you're not expecting? Re-post the code in code tags, as well, please.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top