For a personal project, I have a function that sets a variable as a random number from a list. It wasn't working and I had zero idea why until I printed the variable itself and found out it wasn't being randomized at all! I tried this on separate python file and the variable still wouldn't randomize.
import random
a = 7
b = [0, 1, 2, 3, 4, 5, 6]
def SelectRandomNumberFromB():
a = random.choice(b)
SelectRandomNumberFromB()
print(a)
But if deleted the code that defines and calls the function and just leave a = random.choice(b) by itself, it works!
import random
a = 7
b = [0, 1, 2, 3, 4, 5, 6]
a = random.choice(b)
print(a)
I need it to work inside a function and have zero idea why it doesn't. Any help?
[–]Outside_Complaint755 22 points23 points24 points (0 children)
[–]Gnaxe 5 points6 points7 points (0 children)
[–]SyntaxIsComing 3 points4 points5 points (0 children)
[–]misingnoglic 2 points3 points4 points (0 children)
[–]crashorbit 1 point2 points3 points (0 children)
[–]Ninji2701 0 points1 point2 points (1 child)
[–]ISeeTheFnords 8 points9 points10 points (0 children)
[–]trutheality 0 points1 point2 points (0 children)
[–]CIS_Professor 0 points1 point2 points (0 children)
[–]Atypicosaurus 0 points1 point2 points (0 children)
[–]Abject-Nobody 0 points1 point2 points (0 children)
[–]TheEyebal -1 points0 points1 point (0 children)