I've been trying to fix this but the same error message came up every time:
while number_list[i] <= number_list[j]:
IndexError: list index out of range
I've searched for the same type of bug, but not very similar cases found.
Here it is the head program (orders the numbers of my list, from the little one to the bigger):
number_list=[]
list_lenght=int(input("List lenght: "))
while len(number_list)<list_lenght:
item=input("Enter new item to the list:")
number_list.append(item)
print(number_list)
print("That's your number list: ",number_list)
number_list_final=[]
def order_number_list(number_list):
i=0
j=1
while (j)<=(len(number_list)-1):
while number_list[i]<=number_list[j]:
j=j+1
i=j
j=i+1
final_item=number_list[i]
number_list_final.append(final_item)`
del number_list[i]
order_number_list(number_list)
order_number_list(number_list)
print(number_list_final)
I know this is about iterating with the list while modifying it, but no idea how to fix it.
Can anyone help me to debug this, or give me some tips?
Thank you!