To resolve this issue we can use the following code:
def maiores(lis, n):
maiores_numeros = list()
for c in lis:
if c >= n:
maiores_numeros.append(c)
return maiores_numeros
valores = list(map(int, input('Digite os valores da lista: ').split()))
num = int(input('Desejas retornar os números a partir de qual valor? '))
print(maiores(valores, num))
Note that when we execute this code we receive the following message: Digite os valores da lista:
. Right now we must type all the values, in the same line, separated for a single space and press enter
. From this moment the list values will be mounted with all values typed.
Later we will receive the next message: Desejas retornar os números a partir de qual valor?
. At this point we must enter a integer value which will represent the lower limit of the values we wish to display.
From that moment the list values and the number in a will be passed as parameters to the function major (lis, n). Getting there the block for will iterate over the list lis and, with the help of the block if verify whether the temporary value of the respective iteration - c - is higher hi equal to the value n. If yes, its value will be added to the list most and, later, such list will be displayed as function return.
OBSERVING:
Case, the entered value for the variable in a is a number that is outside the closed range of values belonging to the list values, the return of the function will be a empty list.
Testing code:
Example 1
When we execute the code and enter the following values:
2 9 3 8 4 7
And enter the amount:
5
We will receive as an exit:
[9, 8, 7]
Example 2
When we execute the code and enter the following values:
2 9 3 8 4 7
And enter the amount:
9
We will receive as an exit:
[9]
Example 3
When we execute the code and enter the following values:
2 9 3 8 4 7
And enter the amount:
10
We will receive as an exit:
[]
In this last example we will receive an empty list as a function return. This occurs because it does not exist in the list values numbers greater than or equal to 10.
This structure that you are wanting to do looks a lot like a binary search tree, as the answers are already excellent I will leave my contribution indicating a video about the binary search tree, if you want to take a look is quite enriching: https://www.youtube.com/watch?v=VmKkAQtnjsM&ab_channel=Programa%C3%A7%C3%A3oDin%C3%A2mica
– Elias Oliveira