Jan-20-2019, 07:13 PM
(This post was last modified: Jan-20-2019, 08:15 PM by ichabod801.)
Hello (Please, follow my code below)
This is a portion of a code which use list and function and I took part of the code to best understand the concept
I created a list "palabras" and I assigned there several words
then, I created a function which receive the argument "listaDePalabras"
that argument takes the value when I call the function with:
zona = obtenerPalabraAlAzar(palabras)
inside the function I use the function random to take randomly a word from the list "palabras"
then , I assigned the value in the variable "indiceDePalabras" which return and assign to variable zone to allow print it
But it doesn't work
the error shows:
"list" object is not callable
In short, I want to print a random word from the list using a call from the function
What do I missing here?
I will appreciate any help
Regards,
Jose
Please, follow my code below
This is a portion of a code which use list and function and I took part of the code to best understand the concept
I created a list "palabras" and I assigned there several words
then, I created a function which receive the argument "listaDePalabras"
that argument takes the value when I call the function with:
zona = obtenerPalabraAlAzar(palabras)
inside the function I use the function random to take randomly a word from the list "palabras"
then , I assigned the value in the variable "indiceDePalabras" which return and assign to variable zone to allow print it
But it doesn't work
the error shows:
"list" object is not callable
In short, I want to print a random word from the list using a call from the function
What do I missing here?
I will appreciate any help
Regards,
Jose
Please, follow my code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import random palabras = 'hormiga babuino tejon murcielago oso castor camello gato almeja cobra pantera coyote cuervo ciervo perro burro pato aguila huron zorro rana cabra ganso halcon leon lagarto llama topo mono alce raton mula salamandra nutria buho panda loro paloma piton conejo carnero rata cuervo rinoceronte salmon foca tiburon oveja mofeta perezoso serpiente araña cigüeña cisne tigre sapo trucha pavo tortuga comadreja ballena lobo wombat cebra' .split() def obtenerPalabraAlAzar(listaDePalabras): indiceDePalabras = random.randint( 0 , len (listaDePalabras) - 1 ) return listaDePalabras(indiceDePalabras) zona = obtenerPalabraAlAzar(palabras) print (zona) |