mardi 12 janvier 2016

Python - len(x) doesn't evaluate in parameters?

I'm coding a game where if the user provides a word, the game uses that word. Otherwise, the program should pick a random word from the dictionary. Dictionary is a global list. Currently, the default random will always evaluate to 0, but evaluates correctly anywhere else.

Code:

 def game(i = random.randint(0, len(dictionary))):
    print 'default random:', i
    print 'random inside function:', random.randint(0, len(dictionary))

Output:

default random: 0
random inside function: 40403

Can Python not evaluate len inside parameters?




Aucun commentaire:

Enregistrer un commentaire