I have a function test1()
and in this function, there is a variable w
which is a randomly generated element from a list l
. I want to use the value of w
in another function test2
, but keep the value it generated in test1
. my current code is:
import random
def test1 ():
l = [1,2,3]
w = random.choice(l)
print(w)
def test2 ():
w = test1()
print(w)
test1()
test2()
with the current code, I get two different values for the variable w, I want its value to be randomly generated once, then be able to use that value across different functions.
Aucun commentaire:
Enregistrer un commentaire