[Tutor] I'm having a small problem with my code

David Lifschitz davidthebiglipperlifschitz at gmail.com
Thu May 23 08:16:13 EDT 2019


Hi.
I am currently working on a project for myself.
The code posted here is supposed to ask the user for an amount of numbers,
what those numbers are, and places those numbers in a list.
The next job of the code is to sort the list of numbers that were inputted
in an ascending fashion.
There is no error from the code, however, when I run the code the first
inputted number stays in its place and doesn't get sorted with the rest of
the numbers.
Any advice???

emptyList = []
nOFN = int(input("how many numbers do you want to sort: "))

for x in range(nOFN):
    number1 = int(input("input number: "))
    emptyList.append(number1)
firstElement = emptyList[0]
n = len(emptyList)
for j in range(1, n):
    if emptyList[j-1] > emptyList[j]:
        (emptyList[j-1], emptyList[j]) = (emptyList[j], emptyList[j-1])
print(emptyList)

Sent from an email account


More information about the Tutor mailing list