{"slug":"quadratic","tier":1,"subject":"precalculus","title":"Quadratic Solver","description":"Solves ax^2+bx+c=0 with the quadratic formula.","files":[{"filename":"QUAD.py","content":"def p(s):print(s)\ndef w():input(\"...\")\ndef f():\n a=float(input(\"a:\"))\n b=float(input(\"b:\"))\n c=float(input(\"c:\"))\n d=b*b-4*a*c\n if d<0:p(\"no real\")\n else:\n  r=d**0.5\n  p(\"x1=\"+str((-b+r)/(2*a)))\n  p(\"x2=\"+str((-b-r)/(2*a)))\nf()"}],"testCases":[{"id":"roots-2-1","inputs":["1","-3","2"],"expectedContains":["x1=2.0","x2=1.0"]},{"id":"no-real","inputs":["1","0","1"],"expectedContains":["no real"]}],"usage":"Launch `QUAD` from the `prgm` key. The program will prompt you three times:\n\n1. `a:` — enter the coefficient in front of x² (the leading term).\n2. `b:` — enter the coefficient in front of x.\n3. `c:` — enter the constant term.\n\nPress `enter` after each value. If the discriminant `b²−4ac` is negative, you'll see `no real` — meaning both roots are complex. Otherwise you'll see `x1=` and `x2=` with the two real roots.","example":{"problem":"Solve x² − 3x + 2 = 0.","walkthrough":"Coefficients are a=1, b=−3, c=2.\n\n1. Run `QUAD`.\n2. At `a:` type **1**, press `enter`.\n3. At `b:` type **-3**, press `enter`.\n4. At `c:` type **2**, press `enter`.\n5. Output: `x1=2.0`, `x2=1.0`.\n\nVerify by factoring: (x−2)(x−1) = 0 → x = 2 or x = 1. ✓"}}