python - 如何创建创建和打印正方形列表的代码?
问题描述
我必须编写一个可以创建和打印正方形列表的代码,但不知道该怎么做。到目前为止,我所拥有的是:
import string
import cmath
complex = [(i*3j) for i in range(1,21)]
解决方案
可以使用直接赋值语句或使用 complex() 函数来创建 Python 复数。我已经使用了下面的复杂功能。尝试 :
complx = []
real_ = []
imag_ = []
for i in range(1,21):
num = complex((-9*(i**2)),0)
complx.append(num)
real_.append(num.real)
imag_.append(num.imag)
print('complx:',complx)
print('real:',real_)
print('Imaginary:',imag_)
输出:
complx:
[(-9+0j), (-36+0j), (-81+0j), (-144+0j), (-225+0j), (-324+0j), (-441+0j), (-576+0j), (-729+0j), (-900+0j), (-1089+0j), (-1296+0j), (-1521+0j), (-1764+0j), (-2025+0j), (-2304+0j), (-2601+0j), (-2916+0j), (-3249+0j), (-3600+0j)]
real:
[-9.0, -36.0, -81.0, -144.0, -225.0, -324.0, -441.0, -576.0, -729.0, -900.0, -1089.0, -1296.0, -1521.0, -1764.0, -2025.0, -2304.0, -2601.0, -2916.0, -3249.0, -3600.0]
Imaginary:
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
推荐阅读
- react-native - useEffect 和 useState 未在 fetch 中设置值
- android - 在视图寻呼机 2 中禁用垂直滚动
- excel - 通过 PowerShell 将 .odc 文件导入 Excel
- tensorflow - 在 Keras 中使用空洞卷积
- tensorflow - 在 Keras 中使用空洞卷积
- java - 无法启动 bean 'replyingTemplate';嵌套异常是 java.lang.IllegalStateException:Error handler is not compatible with the message listener
- python - 'NoneType' 对象不可迭代 - 哪里有错误?
- c# - 单击重置按钮 C# 时,我的计时器未重置
- wso2 - 无法根据 WSO2 API 管理器中的消息中介策略调用动态端点/URL
- php - 在 Curl 函数中运行 foreach 循环