1 回答

TA贡献1772条经验 获得超5个赞
确保以Python 期望的确切格式输入数字。
num1 = complex(input("Enter a number: "))
num2 = complex(input("Enter another number: "))
print(f"{num1} + {num2} = {num1 + num2}")
print(f"{num1} - {num2} = {num1 - num2}")
print(f"{num1} * {num2} = {num1 * num2}")
print(f"{num1} / {num2} = {num1 / num2}")
工作得很好(尽管有浮点精度):
$ python3 socom.py
Enter a number: 2.44-77.3333j
Enter another number: 6.83+15j
(2.44-77.3333j) + (6.83+15j) = (9.27-62.333299999999994j)
(2.44-77.3333j) - (6.83+15j) = (-4.390000000000001-92.3333j)
(2.44-77.3333j) * (6.83+15j) = (1176.6646999999998-491.5864389999999j)
(2.44-77.3333j) / (6.83+15j) = (-4.208867770125335-2.0791044579970688j)
添加回答
举报