I am trying to sort this loop algorithmitically:
def tri(t,n):
test= False
while not(test):
for i in range(0,n-1):
if t[i]>t[i 1]:
aux=t[i]
t[i]=t[i 1]
t[i 1]=aux
test = True
print(t,i)
if not(t[i]>t[i 1]):
test=False
print(t)
return t
from numpy import array
t=array([int]*5)
for i in range(5):
t[i]=int(input("t"))
tri(t,5)
the loop appear in the terminal finsished but it is not until i press ctrl c
CodePudding user response:
add break to if in for loop
def tri(t,n):
test= False
while not(test):
for i in range(0,n-1):
if t[i]>t[i 1]:
aux=t[i]
t[i]=t[i 1]
t[i 1]=aux
test = True
print(t,i)
break #here
if not(t[i]>t[i 1]):
print('no')
test=False
print(t)
return t
from numpy import array
t=array([int]*5)
for i in range(5):
t[i]=int(input("t"))
tri(t,5)