lundi 1 février 2021

How do I create changing variables with numpy's random?

I've recently started learning python, and am currently doing datacamp courses. The chapter on np.random has me a bit confused though. I use this code:

import numpy as np
step = 50
dice= np.random.randint(1, 7)
np.random.seed(123)
if dice <= 2 :
    step = step - 1
elif dice >=3 and dice <=5 :
    step = step +1
else :
    step = step + np.random.randint(1,7)
print(dice)
print(step)

Which should result in a random code generated all over when the codeis executed. The problem is, that once Spyder generates the variable dice it stays constant until i reexecute the code that codes it. I know how variables work and all, but datacamp says that simply printing the variable should make it random everytime without restating its value. I something wrong with my code, or maybe it's Spyder's fault as it keeps the variables value? Thanks for all your answers!




Aucun commentaire:

Enregistrer un commentaire