Add text here.Fifty students were surveyed, and asked if they were taking a social science (SS), humanities (HM) or a natural science (NS) course the next quarter.
import matplotlib.pyplot as plt
# The book's survey data. EDIT any number and re-run.
TOTAL = 50
SS, HM, NS = 21, 26, 19 # taking each subject
SS_HM, SS_NS, HM_NS = 9, 7, 10 # taking each pair (includes the all-three students)
ALL3 = 3
only_ss_hm = SS_HM - ALL3
only_ss_ns = SS_NS - ALL3
only_hm_ns = HM_NS - ALL3
only_ss = SS - only_ss_hm - only_ss_ns - ALL3
only_hm = HM - only_ss_hm - only_hm_ns - ALL3
only_ns = NS - only_ss_ns - only_hm_ns - ALL3
inside = (only_ss + only_hm + only_ns + only_ss_hm + only_ss_ns + only_hm_ns + ALL3)
none = TOTAL - inside
print("working from the middle of the diagram outwards")
print(f" all three {ALL3}")
print(f" SS and HM but not NS {SS_HM} - {ALL3} = {only_ss_hm}")
print(f" SS and NS but not HM {SS_NS} - {ALL3} = {only_ss_ns}")
print(f" HM and NS but not SS {HM_NS} - {ALL3} = {only_hm_ns}")
print(f" SS only {SS} - {only_ss_hm} - {only_ss_ns} - {ALL3} = {only_ss}")
print(f" HM only {HM} - {only_ss_hm} - {only_hm_ns} - {ALL3} = {only_hm}")
print(f" NS only {NS} - {only_ss_ns} - {only_hm_ns} - {ALL3} = {only_ns}")
print(f" at least one course {inside}")
print(f" no course {TOTAL} - {inside} = {none}")
if min(only_ss, only_hm, only_ns, only_ss_hm, only_ss_ns, only_hm_ns, none) < 0:
print(" WARNING: a region came out negative - the survey numbers are inconsistent.")
fig, ax = plt.subplots(figsize=(5.6, 5.4))
spots = [(-0.62, 0.42, "SS", only_ss, -1.35, 0.95), (0.62, 0.42, "HM", only_hm, 1.35, 0.95),
(0.0, -0.62, "NS", only_ns, 0.0, -1.55)]
for cx, cy, lab, val, lx, ly in spots:
ax.add_patch(plt.Circle((cx, cy), 1.15, alpha=0.25, lw=2, edgecolor="black"))
ax.text(lx, ly, f"{lab}\n{val}", ha="center", fontsize=12)
for tx, ty, val in ((0.0, 0.66, only_ss_hm), (-0.5, -0.28, only_ss_ns),
(0.5, -0.28, only_hm_ns), (0.0, 0.05, ALL3)):
ax.text(tx, ty, str(val), ha="center", fontsize=12)
ax.text(-1.95, -1.85, f"none: {none}", fontsize=11)
ax.set_xlim(-2.1, 2.1); ax.set_ylim(-2.1, 2.0)
ax.set_aspect("equal"); ax.axis("off")
ax.set_title(f"{TOTAL} students surveyed", fontsize=13)
plt.show()
How many students are only taking a SS course?