When I run this code, "print(x)" will print the same letter every time and yet when I run it like the second example "print(random.choice(b))" it works as expected. What is the difference? I checked for an answer a found references to "seeding" but I am not using random.seed() prior to this.
import random
b = "Hello World"
x = random.choice(b)
print(x)
print(x)
print(x)
# same answer as many times as you want to print
print(random.choice(b))
print(random.choice(b))
print(random.choice(b))
# random choice each time
Aucun commentaire:
Enregistrer un commentaire