{"slug":"complex-mul","tier":1,"subject":"precalculus","title":"Complex Mult","description":"Multiply two complex numbers (a+bi)(c+di).","files":[{"filename":"COMPLEX.py","content":"def p(s):print(s)\ndef o1():\n p(\"=COMP MULT=\")\n a=float(input(\"a:\"))\n b=float(input(\"b:\"))\n c=float(input(\"c:\"))\n d=float(input(\"d:\"))\n r=a*c-b*d\n i=a*d+b*c\n p(\"r=\"+str(r))\n p(\"i=\"+str(i))\ndef menu():\n while True:\n  p(\"=COMPLEX=\")\n  p(\"1:MULT\")\n  p(\"0:EXIT\")\n  c=input(\"?>\")\n  if c==\"1\":o1()\n  elif c==\"0\":break\nmenu()"}],"testCases":[{"id":"one-plus-i-times-two-minus-i","inputs":["1","1","1","2","-1","0"],"expectedContains":["r=3.0","i=1.0"]},{"id":"i-times-i","inputs":["1","0","1","0","1","0"],"expectedContains":["r=-1.0","i=0.0"]}],"usage":"Launch `COMPLEX` from `prgm`. From the main menu pick `1:MULT` to multiply two complex numbers.\n\nFor `(a+bi)(c+di)` the program asks for four numbers in order:\n\n1. `a:` real part of the first number.\n2. `b:` imaginary part of the first number.\n3. `c:` real part of the second number.\n4. `d:` imaginary part of the second number.\n\nOutput is the real part (`r=`) and imaginary part (`i=`) of the product. Press `0` from the menu to exit.","example":{"problem":"Compute (1 + i)(2 − i).","walkthrough":"Here a=1, b=1, c=2, d=−1.\n\n1. Run `COMPLEX`, choose `1:MULT`.\n2. `a:` → **1**, `b:` → **1**, `c:` → **2**, `d:` → **-1**.\n3. Output: `r=3.0`, `i=1.0`.\n\nResult: 3 + i. Verify by FOIL: 1·2 + 1·(−i) + i·2 + i·(−i) = 2 − i + 2i − i² = 2 + i + 1 = 3 + i. ✓"}}