Solutions#

Question 1#

1. Obtain the following tuples using the range command:

1. \((0, 1, 2, 3, 4, 5)\)

tuple(range(6))
(0, 1, 2, 3, 4, 5)

2. \((2, 3, 4, 5)\)

tuple(range(2, 6))
(2, 3, 4, 5)

3. \((2, 4, 6, 8)\)

tuple(range(2, 9, 2))
(2, 4, 6, 8)

4. \(-1, 2, 5, 8\)

tuple(range(-1, 9, 3))
(-1, 2, 5, 8)

Question 2#

2. By both generating and directly computing obtain the number of the following:

1. All permutations of \((0, 1, 2, 3, 4, 5)\).

Generating them all:

import itertools

digits = range(6)
permutations = tuple(itertools.permutations(digits))
permutations
((0, 1, 2, 3, 4, 5),
 (0, 1, 2, 3, 5, 4),
 (0, 1, 2, 4, 3, 5),
 (0, 1, 2, 4, 5, 3),
 (0, 1, 2, 5, 3, 4),
 (0, 1, 2, 5, 4, 3),
 (0, 1, 3, 2, 4, 5),
 (0, 1, 3, 2, 5, 4),
 (0, 1, 3, 4, 2, 5),
 (0, 1, 3, 4, 5, 2),
 (0, 1, 3, 5, 2, 4),
 (0, 1, 3, 5, 4, 2),
 (0, 1, 4, 2, 3, 5),
 (0, 1, 4, 2, 5, 3),
 (0, 1, 4, 3, 2, 5),
 (0, 1, 4, 3, 5, 2),
 (0, 1, 4, 5, 2, 3),
 (0, 1, 4, 5, 3, 2),
 (0, 1, 5, 2, 3, 4),
 (0, 1, 5, 2, 4, 3),
 (0, 1, 5, 3, 2, 4),
 (0, 1, 5, 3, 4, 2),
 (0, 1, 5, 4, 2, 3),
 (0, 1, 5, 4, 3, 2),
 (0, 2, 1, 3, 4, 5),
 (0, 2, 1, 3, 5, 4),
 (0, 2, 1, 4, 3, 5),
 (0, 2, 1, 4, 5, 3),
 (0, 2, 1, 5, 3, 4),
 (0, 2, 1, 5, 4, 3),
 (0, 2, 3, 1, 4, 5),
 (0, 2, 3, 1, 5, 4),
 (0, 2, 3, 4, 1, 5),
 (0, 2, 3, 4, 5, 1),
 (0, 2, 3, 5, 1, 4),
 (0, 2,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
 (5, 4, 0, 3, 2, 1),
 (5, 4, 1, 0, 2, 3),
 (5, 4, 1, 0, 3, 2),
 (5, 4, 1, 2, 0, 3),
 (5, 4, 1, 2, 3, 0),
 (5, 4, 1, 3, 0, 2),
 (5, 4, 1, 3, 2, 0),
 (5, 4, 2, 0, 1, 3),
 (5, 4, 2, 0, 3, 1),
 (5, 4, 2, 1, 0, 3),
 (5, 4, 2, 1, 3, 0),
 (5, 4, 2, 3, 0, 1),
 (5, 4, 2, 3, 1, 0),
 (5, 4, 3, 0, 1, 2),
 (5, 4, 3, 0, 2, 1),
 (5, 4, 3, 1, 0, 2),
 (5, 4, 3, 1, 2, 0),
 (5, 4, 3, 2, 0, 1),
 (5, 4, 3, 2, 1, 0))

Counting them:

len(permutations)
720

Computing the number directly:

import math

math.factorial(6)
720

2. All permutations of \((A, B, C)\).

Generating them all:

letters = ("A", "B", "C")
permutations = tuple(itertools.permutations(letters))
permutations
(('A', 'B', 'C'),
 ('A', 'C', 'B'),
 ('B', 'A', 'C'),
 ('B', 'C', 'A'),
 ('C', 'A', 'B'),
 ('C', 'B', 'A'))

Counting them:

len(permutations)
6

Computing the number directly:

math.factorial(3)
6

3. Permutations of size 3 of \((0, 1, 2, 3, 4, 5)\).

Generating them all:

digits = range(6)
permutations = tuple(itertools.permutations(digits, r=3))
permutations
((0, 1, 2),
 (0, 1, 3),
 (0, 1, 4),
 (0, 1, 5),
 (0, 2, 1),
 (0, 2, 3),
 (0, 2, 4),
 (0, 2, 5),
 (0, 3, 1),
 (0, 3, 2),
 (0, 3, 4),
 (0, 3, 5),
 (0, 4, 1),
 (0, 4, 2),
 (0, 4, 3),
 (0, 4, 5),
 (0, 5, 1),
 (0, 5, 2),
 (0, 5, 3),
 (0, 5, 4),
 (1, 0, 2),
 (1, 0, 3),
 (1, 0, 4),
 (1, 0, 5),
 (1, 2, 0),
 (1, 2, 3),
 (1, 2, 4),
 (1, 2, 5),
 (1, 3, 0),
 (1, 3, 2),
 (1, 3, 4),
 (1, 3, 5),
 (1, 4, 0),
 (1, 4, 2),
 (1, 4, 3),
 (1, 4, 5),
 (1, 5, 0),
 (1, 5, 2),
 (1, 5, 3),
 (1, 5, 4),
 (2, 0, 1),
 (2, 0, 3),
 (2, 0, 4),
 (2, 0, 5),
 (2, 1, 0),
 (2, 1, 3),
 (2, 1, 4),
 (2, 1, 5),
 (2, 3, 0),
 (2, 3, 1),
 (2, 3, 4),
 (2, 3, 5),
 (2, 4, 0),
 (2, 4, 1),
 (2, 4, 3),
 (2, 4, 5),
 (2, 5, 0),
 (2, 5, 1),
 (2, 5, 3),
 (2, 5, 4),
 (3, 0, 1),
 (3, 0, 2),
 (3, 0, 4),
 (3, 0, 5),
 (3, 1, 0),
 (3, 1, 2),
 (3, 1, 4),
 (3, 1, 5),
 (3, 2, 0),
 (3, 2, 1),
 (3, 2, 4),
 (3, 2, 5),
 (3, 4, 0),
 (3, 4, 1),
 (3, 4, 2),
 (3, 4, 5),
 (3, 5, 0),
 (3, 5, 1),
 (3, 5, 2),
 (3, 5, 4),
 (4, 0, 1),
 (4, 0, 2),
 (4, 0, 3),
 (4, 0, 5),
 (4, 1, 0),
 (4, 1, 2),
 (4, 1, 3),
 (4, 1, 5),
 (4, 2, 0),
 (4, 2, 1),
 (4, 2, 3),
 (4, 2, 5),
 (4, 3, 0),
 (4, 3, 1),
 (4, 3, 2),
 (4, 3, 5),
 (4, 5, 0),
 (4, 5, 1),
 (4, 5, 2),
 (4, 5, 3),
 (5, 0, 1),
 (5, 0, 2),
 (5, 0, 3),
 (5, 0, 4),
 (5, 1, 0),
 (5, 1, 2),
 (5, 1, 3),
 (5, 1, 4),
 (5, 2, 0),
 (5, 2, 1),
 (5, 2, 3),
 (5, 2, 4),
 (5, 3, 0),
 (5, 3, 1),
 (5, 3, 2),
 (5, 3, 4),
 (5, 4, 0),
 (5, 4, 1),
 (5, 4, 2),
 (5, 4, 3))

Counting them:

len(permutations)
120

Computing the number directly:

import scipy.special

scipy.special.perm(6, 3)
120.0

4. Permutations of size 2 of \((0, 1, 2, 3, 4, 5, 6)\).

Generating them all:

digits = range(7)
permutations = tuple(itertools.permutations(digits, r=2))
permutations
((0, 1),
 (0, 2),
 (0, 3),
 (0, 4),
 (0, 5),
 (0, 6),
 (1, 0),
 (1, 2),
 (1, 3),
 (1, 4),
 (1, 5),
 (1, 6),
 (2, 0),
 (2, 1),
 (2, 3),
 (2, 4),
 (2, 5),
 (2, 6),
 (3, 0),
 (3, 1),
 (3, 2),
 (3, 4),
 (3, 5),
 (3, 6),
 (4, 0),
 (4, 1),
 (4, 2),
 (4, 3),
 (4, 5),
 (4, 6),
 (5, 0),
 (5, 1),
 (5, 2),
 (5, 3),
 (5, 4),
 (5, 6),
 (6, 0),
 (6, 1),
 (6, 2),
 (6, 3),
 (6, 4),
 (6, 5))

Counting them:

len(permutations)
42

Computing the number directly:

import scipy.special

scipy.special.perm(7, 2)
42.0

5. Combinations of size 3 of \((0, 1, 2, 3, 4, 5)\).

Generating them all:

digits = range(6)
combinations = tuple(itertools.combinations(digits, r=3))
combinations
((0, 1, 2),
 (0, 1, 3),
 (0, 1, 4),
 (0, 1, 5),
 (0, 2, 3),
 (0, 2, 4),
 (0, 2, 5),
 (0, 3, 4),
 (0, 3, 5),
 (0, 4, 5),
 (1, 2, 3),
 (1, 2, 4),
 (1, 2, 5),
 (1, 3, 4),
 (1, 3, 5),
 (1, 4, 5),
 (2, 3, 4),
 (2, 3, 5),
 (2, 4, 5),
 (3, 4, 5))

Counting them:

len(combinations)
20

Computing the number directly:

import scipy.special

scipy.special.comb(6, 3)
20.0

6. Combinations of size 2 of \((0, 1, 2, 3, 4, 5)\).

Generating them all:

digits = range(6)
combinations = tuple(itertools.combinations(digits, r=2))
combinations
((0, 1),
 (0, 2),
 (0, 3),
 (0, 4),
 (0, 5),
 (1, 2),
 (1, 3),
 (1, 4),
 (1, 5),
 (2, 3),
 (2, 4),
 (2, 5),
 (3, 4),
 (3, 5),
 (4, 5))

Counting them:

len(combinations)
15

Computing the number directly:

import scipy.special

scipy.special.comb(6, 2)
15.0

7. Combinations of size 5 of \((0, 1, 2, 3, 4, 5)\).

Generating them all:

digits = range(6)
combinations = tuple(itertools.combinations(digits, r=5))
combinations
((0, 1, 2, 3, 4),
 (0, 1, 2, 3, 5),
 (0, 1, 2, 4, 5),
 (0, 1, 3, 4, 5),
 (0, 2, 3, 4, 5),
 (1, 2, 3, 4, 5))

Counting them:

len(combinations)
6

Computing the number directly:

import scipy.special

scipy.special.comb(6, 5)
6.0

Question 3#

3. A class consists of 3 students from Ashville and 4 from Bewton. A committee of 5 students is chosen at random the class.

1. Find the number of committees that include 2 students from Ashville and 3 from Bewton are chosen.

We directly enumerate them:

students = ("Ashville", "Ashville", "Ashville", "Bewton", "Bewton", "Bewton", "Bewton")
committees = tuple(itertools.combinations(students, 5))
committees
(('Ashville', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Bewton'))

Selecting only the ones with 2 Ashville students (if there are 2 Ashville students then there are 3 Bewton ones):

sum(1 for committee in committees if committee == ("Ashville", "Ashville", "Bewton", "Bewton", "Bewton"))
12

2. In fact 2 students, from Ashville and 3 from Bewton are chosen. In order to watch a video, all 5 committee members sit in a row. In how many different orders can they sit if no two students from Bewton sit next to each other.

To answer this we need to consider committees as permutations (as order matters):

committee = ("Ashville", "Ashville", "Bewton", "Bewton", "Bewton")
seating_arrangements = tuple(itertools.permutations(committee))
seating_arrangements
(('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Ashville', 'Bewton', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Ashville', 'Bewton', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Ashville', 'Bewton', 'Bewton', 'Ashville', 'Bewton'),
 ('Ashville', 'Bewton', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Ashville', 'Bewton', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Ashville', 'Bewton', 'Ashville', 'Bewton'),
 ('Bewton', 'Ashville', 'Bewton', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Ashville', 'Ashville', 'Bewton'),
 ('Bewton', 'Bewton', 'Ashville', 'Bewton', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'),
 ('Bewton', 'Bewton', 'Bewton', 'Ashville', 'Ashville'))

For no two students from Bewton to site next to each other the order is fixed:

sum(
    1
    for seating_arrangement in seating_arrangements
    if seating_arrangement == ("Bewton", "Ashville", "Bewton", "Ashville", "Bewton")
)
12

Question 4#

4. Three letters are selected at random from the 8 letters of the word COMPUTER, without regard to order.

1. Find the number of possible selections of 3 letters.

letters = ("C", "O", "M", "P", "U", "T", "E", "R")
selections = tuple(itertools.combinations(letters, 3))
selections
(('C', 'O', 'M'),
 ('C', 'O', 'P'),
 ('C', 'O', 'U'),
 ('C', 'O', 'T'),
 ('C', 'O', 'E'),
 ('C', 'O', 'R'),
 ('C', 'M', 'P'),
 ('C', 'M', 'U'),
 ('C', 'M', 'T'),
 ('C', 'M', 'E'),
 ('C', 'M', 'R'),
 ('C', 'P', 'U'),
 ('C', 'P', 'T'),
 ('C', 'P', 'E'),
 ('C', 'P', 'R'),
 ('C', 'U', 'T'),
 ('C', 'U', 'E'),
 ('C', 'U', 'R'),
 ('C', 'T', 'E'),
 ('C', 'T', 'R'),
 ('C', 'E', 'R'),
 ('O', 'M', 'P'),
 ('O', 'M', 'U'),
 ('O', 'M', 'T'),
 ('O', 'M', 'E'),
 ('O', 'M', 'R'),
 ('O', 'P', 'U'),
 ('O', 'P', 'T'),
 ('O', 'P', 'E'),
 ('O', 'P', 'R'),
 ('O', 'U', 'T'),
 ('O', 'U', 'E'),
 ('O', 'U', 'R'),
 ('O', 'T', 'E'),
 ('O', 'T', 'R'),
 ('O', 'E', 'R'),
 ('M', 'P', 'U'),
 ('M', 'P', 'T'),
 ('M', 'P', 'E'),
 ('M', 'P', 'R'),
 ('M', 'U', 'T'),
 ('M', 'U', 'E'),
 ('M', 'U', 'R'),
 ('M', 'T', 'E'),
 ('M', 'T', 'R'),
 ('M', 'E', 'R'),
 ('P', 'U', 'T'),
 ('P', 'U', 'E'),
 ('P', 'U', 'R'),
 ('P', 'T', 'E'),
 ('P', 'T', 'R'),
 ('P', 'E', 'R'),
 ('U', 'T', 'E'),
 ('U', 'T', 'R'),
 ('U', 'E', 'R'),
 ('T', 'E', 'R'))

Counting them:

len(selections)
56

Note that a string is in fact an iterable so we can also do:

letters = "COMPUTER"
selections = tuple(itertools.combinations(letters, 3))
len(selections)
56

2. Find the number of selections of 3 letters with the letter P.

sum(1 for selection in selections if "P" in selection)
21

3. Find the number of selections of 3 letters where the 3 letters form the word TOP.

sum(1 for selection in selections if sorted(selection) == sorted(("O", "P", "T")))
1