I attempted to do it without using .sort() or the sorted function.
I used a simple sorting algorithm that’s not in-place (and is not efficient):
first create a list of boolean values to keep track of whether a given index has been used yet
in a loop
find the smallest number in the list that for the indices that are marked as not used yet
when that smallest number is found, increment the counter, and mark the index of that number as used
stop when the counter reaches n (if we’re trying to find the n^{th} number).

code for the function

def getX(x, nums):
used = [False for n in nums]
#ordered = [None for n in nums]
length = len(nums)
if length is 0 or x > length or x < 1:
return 0
min_so_far = nums[0]
index_of_min = 0
for i in range(x): # i counts how many numbers so far
started = False
for j in range(length):
n = nums[j]
if used[j] is False and (n < min_so_far or not started):
min_so_far = n
index_of_min = j
started = True
#endfor
#ordered[i] = min_so_far
used[index_of_min] = True
#endfor
return min_so_far

This is very similar to an earlier post by @lucemile.
I also see that others used bubble sort or sorting algorithms similar to that, for example the post by @digital9933512222

def getX(x, nums):
if x > len(nums) or len(nums) == 0:
return 0
else:
nums.sort()
for i in range(len(nums)):
if i == x-1:
return nums[i]
print(getX(2, [6, 3, -1, 5]))

On looking over your code, I don’t think it works as to its intended purpose. We want the nth number of a sequence, correct? Where does sorting come into play? That will jumble the sequence, won’t it?

There are a number of ways to validate a sequence. We’re going direct to the object to obtain the vital information:

y = hasattr(nums, '__iter__')

That tells us whether nums is iterable, or not. Now we’ve validated it for that feature, we next can cache the length;

n = len(nums)

As much as we would like to write,

if y and n:

we cannot. Non-sequential values don’t have a length. So we have to put the latter assignment inside an if.

if y:
n = ...
else:
raise TypeError

What happens next is still to be resolved. We need to be sure that n is non-zero. Allowing for that, we now need to validate the index value in the arguments. Is x in range?

k = x in range(1, n + 1)

Those are all the test conditions. Did you catch the sneaky two birds with one stone? Now we only have to return the value at the requested position.

if k:
return nums[x-1]
else:
raise IndexError # this happens if n is zero or x is out of range

def getX(x, nums):
# write your code here
# first we sort the list
s_nums = sorted(nums)
# we need to go one index back, because the list starts with index 0
x = x - 1
# condition: if x is equal or smaller than the last index and equal or higher than the first index
if (x <= len(s_nums) - 1 and x >= 0):
return s_nums[x]
# if above argument is not true return 0
else:
return 0
print(getX(2, [6, 3, -1, 5]))