Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why are there spaces when I do print x,x,x?
#1
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)
Reply
#2
I get a syntax error anyways.
Reply
#3
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 ,
[Image: nv70ad.png]
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Reply
#4
(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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] print a random variable? nevets04 2 1,783 10-11-2009, 06:42 PM
Last Post: nevets04

Forum Jump:


Users browsing this thread: 1 Guest(s)