mardi 22 août 2017

new to python: why does random.choice() produce correctly when alone but when placed in a name expression it doesnt

if i do random.choice by itself, i get the desired result, if i place it in a name expression i dont. reason i ask is because im making a rock paper scissor game and i need the computer to randomly choose between the three, and from what ive read its not practical to use random.choice all on its lonesome, what would be the ideal solution, thanks.

Ex:

>>> import random
>>> l = [1,2,3]
>>> comprandom = random.choice(l)
>>> comprandom
1
>>> comprandom
1
>>> comprandom
1
>>> comprandom
1
>>> comprandom
1
>>> comprandom
1
>>> random.choice(l)
3
>>> comprandom
1
>>> 




Aucun commentaire:

Enregistrer un commentaire