mardi 5 février 2019

Unable to set a new variable after using the random command in Python

I'm very new to Python and I'm having an issue setting a new variable after using the random command.

Here is my sample code:

import random

foo = ['a', 'b']
print("foo is: " + random.choice(foo))

if foo == 'a':
    randomLetter = 'a'
else:
    randomLetter = 'b'

print(randomLetter)

No matter what foo equals, randomLetter always equals b.

I'm not sure what I am doing wrong. Any help with be appreciated.




Aucun commentaire:

Enregistrer un commentaire