'Not receiving any output from my function

currently I am attempting to solve a problem that reads as follows:

 Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed.

Example

For statues = [6, 2, 3, 8], the output should be
solution(statues) = 3.

Ratiorg needs statues of sizes 4, 5 and 7.

The following is the solution that I have come up with:

def solution(statues):
    statues.sort()
    n = 0
    needed = 0
    additor = 1
    while n > len(statues):
        if (statues[n] + 1) == statues[n+1]:
            n+=1
        else:
            while (statues[n] + additor) != statues[n+1]:
                needed +=1
                additor +=1
            n+=1
    return needed

2/5 of my tests are passing, but for some reason the rest are not. When I view my outputs I am getting 0 and empty so it is clear that the variable needed is not updating through my loops. Can anyone give me some guidance on this issue? It seems like I am not properly understanding how to manage my variables both inside and outside different loops.



Solution 1:[1]

while n > len(statues):

This could be the issue, n is initialised as 0 and the entry condition is while n greater than len(statues) which is 4

Solution 2:[2]

This can be a possible solution-

import numpy as np

statues = [6, 2, 3, 8]

def function_statue(statues):
    min_no = np.min(statues)
    max_no = np.max(statues)
    
    c= 0
    for no in range(min_no, max_no):
        if no in statues:
            pass
        else:
            c=c+1    
    return c

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pickplatespiral
Solution 2 lsr729