如何用Python继续编写这个题

如题所述

#-*-coding:utf-8-*-
import math

''' 定义a, b'''
a, b = 3, 4

'''自定义输入一个虚数的实部和虚部'''
input_real = float(input('Enter the real part of the complex number: '))
input_imag = float(input('Enter the imaginary part of the complex number: '))

'''初始化两个虚数'''
c1, c2 = complex(a, b), complex(input_real, input_imag)

'''计算出product1'''
product1 = c1*c2

'''按要求计算出两个角的度数'''
r1 = abs(c1)
theta1 = math.atan2(b,a)
r2 = complex(math.sqrt(input_real), input_imag)
theta2 = math.atan2(input_imag, input_real)

'''根据计算出的两个角度计算product2'''
product2 = r1*r2*complex(math.cos(theta1+theta2), math.sin(theta1+theta2))

print(product1*product2, product1-product2)




根据楼主的需求写了代码,最后逗计算product1和product2乘积的差值逗实在难以理解,就随手打印了两个值。


其实整个题目就是代入公式,掌握以下几点就不难解了:
1)定义虚数python中使用的是complex(实部, 虚部)的形式定义
2)python中绝对值是使用abs(x)函数来实现
3)math中提供了sqrt(x)(求x的平方根),atan2(y, x)(求y/x的arctan值)的方法


建议楼主以后问问题的时候排一下版(因为看起来真的很累),这样会增加回答者的效率。希望以上回答能够解决您的问题,谢谢!

温馨提示:答案为网友推荐,仅供参考
相似回答