I'm a novice in Python and my homework is to take a list with a bunch of numbers in it and
- make the list ordered from lowest number to highest
- get rid of duplicate numbers.
This must be accomplished with loops
My code so far:
numbers = [84, 79, 66, 69, 79, 82, 78, 79, 84, 84, 79, 66, 69, 84,
72, 65, 84, 73, 83, 84, 72, 69, 81, 85, 69, 83, 84, 73, 79, 78]
ordered = []
while numbers != []:
min = numbers[0]
for i in range(0, len(numbers)):
if numbers[i] < min:
min = numbers[i]
ordered.append(min)
j = 0
while j < len(numbers):
if numbers[j] == min:
numbers.pop(j)
j += 1
print(ordered)
And the output:
[65, 66, 69, 72, 73, 78, 79, 79, 81, 82, 83, 84, 84, 84, 85]
So task1 is okay but task2 is only accomplished at some points not all. I can't figure out why? Thank you in advance for any help! P.S.: I already solved the problem in another way but it just keeps bugging me why this posted idea of mine didn't work.