1
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!

stickywicket
  • 91
  • 1
  • 9

3 Answers3

3

The problem with your code is that print(p,"-",p2) will print spaces between its arguments, better use print("{}-{}".format(p, p2)).

mpcabd
  • 1,813
  • 15
  • 20
2

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)
Saket Mittal
  • 3,726
  • 3
  • 29
  • 49
1

This is because of print. You need to concat password into single variable like that: password = '%s-%s' % (p, p2)