# Error invalid literal for int () with base 10

2

Hello friends, I'm creating a program in Python and it gives me that error. Here is my code to know if you can help me, thank you very much

``````def calculoMediana(list):
mediana = float(0)
tamaño = len(list)
if tamaño %2 ==0:
mediana = (list[(tamaño // 2)] + list[(tamaño //2)-1])/2
return mediana
else:
mediana = list[(tamaño//2)]
return mediana

def lista():
continuar = "SI"
while continuar.upper() == "SI":
n = int(input("Ingrese el tamaño del que desea su lista:"))
list = []
valor = int(input("Favor ingrese un valor de la lista:"))
list.append(valor)
list.sort()
print (calculoMediana(list))
continuar = input("Desea continuar (SI/NO)?")

try:
lista()

except ValueError:
print("Favor ingrese un numero entero")
pass
lista()
``````

my mistake says

valueerror invalid literal for int () with base 10: 'm'

and then I do not care, but

valueerror invalid literal for int () with base 10: 'p'

asked by Elias Arias 03.10.2017 в 03:58
source

2

So much in this line

`````` n = int(input("Ingrese el tamaño del que desea su lista:"))
``````

as in this

``````valor = int(input("Favor ingrese un valor de la lista:"))
``````

you are waiting for a value of numeric type to assign it to the variable, since it is being converted to an integer by `int()` , if you enter a non-numeric value, you will get the error:

invalid literal for int () with base 10:

Actually you have an exception handling but when you do it you are calling the function `lista()` , which does not have defined exception handling, as an option you could avoid calling this method and in this way your program would end indicating that you should enter an entire number:

``````try:
lista()

except ValueError:
print("Favor ingrese un numero entero")
#pass
#lista()
``````