Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2 

3"""Solution to chapter 6, exercise 27: makepw""" 

4 

5import random 

6 

7 

8def create_password_generator(characters): 

9 """This function takes a string as input. 

10 

11It returns a function that, when invoked with an 

12integer argument, returns a string containing 

13a random selection from "characters", of length 

14"length". 

15""" 

16 def create_password(length): 

17 output = [] 

18 

19 for i in range(length): 

20 output.append(random.choice(characters)) 

21 return ''.join(output) 

22 return create_password