0
Can you guys help me in shortening my code ?
3 Answers
+ 1
I have shortened it a bit. Please ask if you don't understand one of the changes.
from random import choice
a = "abcdefghijklmnopqrstuvwxyz"
a += a.upper()
b = "0123456789"
c = "!@#amp;"
d = ""
for i in range(4):
d += choice(a)
for i in range(4):
d += choice(b)
for i in range(4):
d += choice(c)
print(d)
+ 1
import random
import string
mychars, mynumbers, mysymbols = string.ascii_letters, string.digits, "!@#amp;"
d = ''.join(random.choices(mychars, k=4) +
random.choices(mynumbers, k=4) +
random.choices(mysymbols, k=2))
print(d)
0
Thanks Honfu