Support Forums
Why are there spaces when I do print x,x,x? - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: Why are there spaces when I do print x,x,x? (/showthread.php?tid=2361)



Why are there spaces when I do print x,x,x? - nevets04 - 10-30-2009

Why are there spaces in between the letters number and symbols? how do I get rid of them?
Code:
import os
import random
while True:
    a = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
    b = [1,2,3,4,5,6,7,8,9]
    c = [',','.',';',':','-','+']
    d = ['!','@','#','$','%','^','&','*','(',')']
    e = random.choice(a)
    f = random.choice(b)
    g = random.choice(c)
    h = random.choice(d)
    i = [e,f,g,h]
    j = random.choice(i)
    k = int(raw_input("How Many characters should be in your password?: "))
    if k == 1:
        print random.choice(i)
    elif k == 2:
        print random.choice(i),random.choice(i)
    elif k == 3:
        print random.choice(i),random.choice(i),random.choice(i)
    elif k == 4:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 5:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 6:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 7:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 8:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 9:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 10:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 11:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 12:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 13:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 14:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 15:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)
    elif k == 16:
        print random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i),random.choice(i)



RE: Why are there spaces when I do print x,x,x? - Yoshi - 10-31-2009

I get a syntax error anyways.


RE: Why are there spaces when I do print x,x,x? - Fallen - 10-31-2009

Code:
import os, random
while True: print "".join([str(random.choice([random.choice(['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']),random.choice([1,2,3,4,5,6,7,8,9]),random.choice([',','.',';',':','-','+']),random.choice(['!','@','#','$','%','^','&','*','(',')'])]))for x in xrange(int(raw_input("How Many characters should be in your password?: ")))])

and you are printing a tuple, you want to do + instead of ,


RE: Why are there spaces when I do print x,x,x? - nevets04 - 10-31-2009

(10-31-2009, 08:15 AM)Fallen Wrote:
Code:
import os, random
while True: print "".join([str(random.choice([random.choice(['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']),random.choice([1,2,3,4,5,6,7,8,9]),random.choice([',','.',';',':','-','+']),random.choice(['!','@','#','$','%','^','&','*','(',')'])]))for x in xrange(int(raw_input("How Many characters should be in your password?: ")))])

and you are printing a tuple, you want to do + instead of ,

Can you split that into multiple stings?