Skip to content Skip to sidebar Skip to footer

Further Beginner Spam Work In Python

I used to be able to get my string of 10 characters to contain uppercase and lowercase letters, as well as numbers. Now all I am getting is a string of lowercase characters. What d

Solution 1:

The answer to your question why did it change, is because you are only picking from a in your random.choice.

There is a much simpler way to do this:

>>> import random
>>> import string
>>> random.sample(string.letters+string.digits, 10)
['e', 'l', 'b', 'q', 'k', 'T', 'K', 'H', 'B', 'w']
>>> random.sample(string.letters+string.digits, 10)
['5', 'g', 't', 'k', 'W', 'u', '4', 'T', '6', 'C']
>>> random.sample(string.letters+string.digits, 10)
['z', 'N', 'y', 'O', 'L', 'r', '6', 'D', 'V', '8']

Solution 2:

Your assignment to rs only chooses values from a, so you won't get any upper-case letters or digits in your string.


Solution 3:

a = ('abcdefghijklmnopqrstuvwxyz')
...
rs = (random.choice(a)) + (random.choice(a)) + (random.choice(a)) + (random.choice(a)) + (random.choice(a)) + (random.choice(a)) + (random.choice(a)) + (random.choice(a)) + (random.choice(a)) + (random.choice(a))

Since a consists only of lowercase letters, so does rs.


Post a Comment for "Further Beginner Spam Work In Python"