You will write three small functions that count the regions of a Venn diagram. The checker uses a class of students, two clubs and three sets of numbers.
The idea. Fill in the overlap first. The number in only one set is its total minus the overlap. The number in neither set is the total minus the union.
Your tasks.
only_a(n_a, n_both). Return the number of elements in set only.neither(total, n_a, n_b, n_both). Return the number of elements in neither set.union_three(a, b, c). The three sets are Python sets. Return the number of elements in by adding the sets, subtracting the pair overlaps and adding the centre back.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…