Bit strings
A bit string is a sequence of bits (0 or 1). For example, 00001111 and 1011010 are bit strings of length 7. Bit strings can be used to represent sets or to manipulate binary data. Can you count how many different bit strings of length 7 there are?
By the product rule we get the count
2* 2 * 2 * 2 * 2 * 2 *2 = 27 = 128
Valid passwords
As a system administrator, you are asked to design a username policy for the login system. How many different usernames can be formed with five letters, followed by one number?
The letters can be any of 52 (26 lowercase letters and 26 capital letters), and the numbers can be any of 10 (0…9).
The number of possible combinations is 525 * 10, which is approximately 144555105949057020, more than a hundred quadrillion. This is probably more logins than the website would need!
In Python3, ascii_lowercase
is a pre-initialized string used as string constant. Its value is abcdefghijklmnopqrstuvwxyz
. Similarly, ascii_uppercase
holds all the uppercase letters. To use them, we will need to import
the string
module, as these constants are not built-in.
Instructions
Let us explore the power of Python by writing code to find a large number of password combinations.
The workspace already has code to create three lists:
import string lower_list = list(string.ascii_lowercase) upper_list = list(string.ascii_uppercase) number_list = list(range(0,10))
Write Python code to list all password combinations beginning with a lowercase letter, followed by one uppercase letter and one number.
A count
variable has already been initialized to 0. Increment it within the nested loop and print
the final count
of possibilities.