Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list
#1
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

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)
Reply


Messages In This Thread
list - by josesalazmit - Jan-20-2019, 07:13 PM
RE: list - by Larz60+ - Jan-20-2019, 07:37 PM
RE: list - by ichabod801 - Jan-20-2019, 08:16 PM
RE: list - by stullis - Jan-20-2019, 10:21 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020