I have recently been trying to code a number sorter. I searched the internet and decided to try out this piece of code:
numbers=([])
amount=input("How many numbers are in your list? ")
print("")
counter = 0
ran = 0
while counter < int(amount):
counter = counter + 1
ran = ran + 1
num3 = input(str(ran) + ". Input: ")
try:
val = int(num3)
except ValueError:
num3 = input(str(ran) + ". Input: ")
sort(numbers)
numbers.append(num3)
At the beginning (when I try to run it), it seems to work; here are the first few lines of output:
How many numbers are in your list? (I input 7)
1. Input: (I input 3)
But then, this error appears right after I input 3 and press enter:
Traceback (most recent call last):
File "D:/ZGMDCL8364/Documents/AllPyCharmProjects001/NumberSorter.py", line 39, in <module>
sort(numbers)
NameError: name 'sort' is not defined
And then I get this:
Process finished with exit code 1
How do I fix this? Please help.