Welcome, guest | Sign In | My Account | Store | Cart
##Author: ATC
##Please score this on activestate

import string, random

print "How many characters would you like the password to have?"
print "Must be nine or more"
length = input ()


password_len = length

password = []

for group in (string.ascii_letters, string.punctuation, string.digits):
    password += random.sample(group, 3)

password += random.sample(
                 string.ascii_letters + string.punctuation + string.digits,
                 password_len - len(password))

random.shuffle(password)
password = ''.join(password)


print password

Diff to Previous Revision

--- revision 3 2011-10-12 15:01:05
+++ revision 4 2011-10-14 13:35:21
@@ -1,32 +1,26 @@
-## Author Alex Cruz
-## Remember to score me on ActiveState
+##Author: ATC
+##Please score this on activestate
+
 import string, random
 
+print "How many characters would you like the password to have?"
+print "Must be nine or more"
+length = input ()
 
-def main():
-    total = string.ascii_letters + string.punctuation + string.digits
-    password = ''.join(random.sample(total, 30))
-    while not approved(password):
-        password = ''.join(random.sample(total, 30))
-    print(password)
 
-def approved(password):
-    group = select(password[0])
-    for character in password[1:]:
-        trial = select(character)
-        if trial is group:
-            return False
-        group = trial
-    return True
+password_len = length
 
-def select(character):
-    for group in (string.ascii_uppercase,
-                  string.ascii_lowercase,
-                  string.punctuation,
-                  string.digits):
-        if character in group:
-            return group
-    raise ValueError('Character was not found in any group!')
+password = []
 
-if __name__ == '__main__':
-    main()
+for group in (string.ascii_letters, string.punctuation, string.digits):
+    password += random.sample(group, 3)
+
+password += random.sample(
+                 string.ascii_letters + string.punctuation + string.digits,
+                 password_len - len(password))
+
+random.shuffle(password)
+password = ''.join(password)
+
+
+print password

History