Answer the question
In order to leave comments, you need to log in
The condition statement does not work in a function with return, how to fix it?
The function returns not None only if the numbers already arranged in the correct order are run through it. The task of the function to sort from largest to smallest is completely confused (yes, I understand that this code is one big complication, but it needs to work in this form).
def terra(num):
exit = len(num) - 1
for i in range(len(num)-1):
if num[i] < num[i + 1]:
b = num[i + 1]
num.pop(i + 1)
num.insert(i,b)
elif num[i] >= num[i + 1]:
exit = exit - 1
if exit == 0:
return num
else:
terra(num)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question