trying to generate random passwords with "-" in between
Question:
import random
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
passlen = 4
p = "".join(random.sample(s,passlen))
p2 = "".join(random.sample(s,passlen))
print(p,"-",p2)
This is my code. But when i run it get something like this: RJ9e – zN0P
I do not need the spaces in between. What am i missing here?
Thanks!
Answers:
The problem with your code is that print(p,"-",p2)
will print spaces between its arguments, better use print("{}-{}".format(p, p2))
.
This is because of print. You need to concat password into single variable like that:
password = '%s-%s' % (p, p2)
just concat all string into single string using ‘+’ operator
import random
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
passlen = 4
p = "".join(random.sample(s,passlen))
p2 = "".join(random.sample(s,passlen))
print(p+"-"+p2)
import random
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
passlen = 4
p = "".join(random.sample(s,passlen))
p2 = "".join(random.sample(s,passlen))
print(p,"-",p2)
This is my code. But when i run it get something like this: RJ9e – zN0P
I do not need the spaces in between. What am i missing here?
Thanks!
The problem with your code is that print(p,"-",p2)
will print spaces between its arguments, better use print("{}-{}".format(p, p2))
.
This is because of print. You need to concat password into single variable like that:
password = '%s-%s' % (p, p2)
just concat all string into single string using ‘+’ operator
import random
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
passlen = 4
p = "".join(random.sample(s,passlen))
p2 = "".join(random.sample(s,passlen))
print(p+"-"+p2)