Q:

As I do so as not to show the -1 in the Python list

Write a function to enter from the keyboard a series of numbers between 1 and 20 and save them in a list.In case of entering an out-of-range value the program will display an error message and ask for a new number.To finish loading you must enter -1.La function does not receive any parameters, and returns the loaded list (or empty, if the user did not enter anything) as the return value.
def funcion():
list = []
num = 0
while num != -1:
    num = int(input("Enter a number between 1 and 20: "))
    while num > 20 :
        num = int(input("Please re-enter the number: "))
    list.append(num)
return lista
result = funcion()
print(result)

My question is how I do not show the -1 in the list

A:

It's easier to have an infinite loop and break out of it when the user enters -1:
def funcion():

    lista = []
    num = 0
    while True:
        num = int(input("Enter a number between 1 and 20: "))
        while num > 20:
            num = int(input("Please re-enter the number: "))
        if num == -1:
            break
        else:
            lista.append(num)
    return lista

result = funcion()
print(result)

