接收用户输入的一个复数的实部和虚部,输出其复数表示形式,并求其模。
运行代码如下:
方法一:
import math
x = input("请输入一个复数的实部和虚部:")
a, b = map(float, x.split())
c = complex(a, b)
d = abs(c)
print("输入的复数为:" + str(c), ",模为:" + str(d))
运行截图:
方法二:
import math
a = input("请输入一个复数的实部:")
b = input("请输入一个复数的虚部:")
c = math.sqrt(float(a) ** 2 + float(b) ** 2)
print("输入的复数为:" + a + "+" + b + "j", ",模为:" + str(c))
运行截图: