import string
import random

passwords = {}
pw_length = 8
allowed_characters = string.ascii_letters + string.punctuation  + string.digits

def generate_pw(n, allowed):
    pw = ''
    for i in range(pw_length):
        pw += random.choice(allowed)
    return pw

selection = input("(r)etrieve or (g)enerate password? ")
if selection == 'r':
    print(passwords.keys())
    print(passwords[input("Which password would you like? ")])
elif selection == 'g':
    passwords[input("Enter account name: ")] = generate_pw(pw_length, allowed_characters)

@@ -51,16 +51,29 @@
 gth = 8%0A
+exit = False%0A
 allowed_
@@ -269,16 +269,36 @@
 urn pw%0A%0A
+while not exit:%0A    
 selectio
@@ -322,11 +322,9 @@
 ieve
- or
+,
  (g)
@@ -343,13 +343,27 @@
 word
+ or (q)uit
 ? %22)%0A
+    
 if s
@@ -379,24 +379,28 @@
 == 'r':%0A    
+ 
+   
 print(passwo
@@ -411,16 +411,20 @@
 keys())%0A
+    
     prin
@@ -478,16 +478,20 @@
 e? %22)%5D)%0A
+    
 elif sel
@@ -509,16 +509,20 @@
 g':%0A    
+ 
+   
 password
@@ -599,8 +599,55 @@
 acters)%0A
+    elif selection == 'q':%0A        exit = True%0A

correct example script