{"slug":"sample-sd","tier":1,"subject":"statistics","title":"Sample SD","description":"Sample standard deviation of n values.","files":[{"filename":"SAMPLESD.py","content":"def p(s):print(s)\ndef o1():\n p(\"=SD=\")\n n=int(input(\"n:\"))\n vs=[]\n for i in range(n):vs.append(float(input(\">\")))\n m=sum(vs)/n\n v=0.0\n for x in vs:v+=(x-m)*(x-m)\n sd=(v/(n-1))**0.5\n p(\"sd=\"+str(sd))\ndef menu():\n while True:\n  p(\"=SAMPLE SD=\")\n  p(\"1:SD\")\n  p(\"0:EXIT\")\n  c=input(\"?>\")\n  if c==\"1\":o1()\n  elif c==\"0\":break\nmenu()"}],"testCases":[{"id":"four-all-4","inputs":["1","4","2","4","4","4","0"],"expectedContains":["sd=1.0"]},{"id":"three-1-2-3","inputs":["1","3","1","2","3","0"],"expectedContains":["sd=1.0"]}],"usage":"Computes the **sample** standard deviation (divides by `n−1`, not `n`). Use this for samples in AP Stats / inferential work; for a full population you'd need the population formula.\n\nLaunch `SAMPLESD` from `prgm`, choose `1:SD`, then:\n\n1. `n:` — how many values you'll enter.\n2. `>` — type each value one at a time, `enter` between each.\n\nOutput is `sd=`. Program returns to the menu; `0:EXIT` to leave.","example":{"problem":"Find the sample standard deviation of the test scores {1, 2, 3}.","walkthrough":"1. Run `SAMPLESD`, choose `1:SD`.\n2. `n:` → **3**.\n3. `>` → **1**, **2**, **3** (pressing `enter` between each).\n4. Output: `sd=1.0`.\n\nVerify: mean = 2. Squared deviations = (1−2)² + (2−2)² + (3−2)² = 1 + 0 + 1 = 2. Sample variance = 2/(3−1) = 1. SD = √1 = 1. ✓"}}