#Definir una función que calcule la longitud de una lista
# o una cadena
def longi(numero,lista):
lista = [1,2,3,4,5,36,7,8,9,3,4,5,6,7,5,4,3,4]
numero = 0
for i in lista:
numero = numero + 1
print(numero)
longi(numero,lista)
I am trying to define a function which counts how many numbers have a list, but when calling the function with the arguments it tells me that they are not defined. Does anyone know why?
If you are going to call a function, you have to have the parameters beforehand, like here:
The function
longi
requires thatnumero
andlista
are already defined.The function
longi
boils down to this:It's a bad idea to do input/output inside functions though (unless that's your specific purpose). It is better to just return the value and the caller will take care of printing it.
show
produces: