【发布时间】:2021-07-24 14:26:56
【问题描述】:
我想获得一个 0.0 与 0.0 到 0.9 的乘积的列表。然后是 0.1 到 0.9。等等。所以我列表中的元素总数必须为 100。此代码不起作用。有什么帮助吗?
p=0.0
dp=0.1
p_ray= []
while p < 0.9:
t = 0.0
dt = 0.1
t_ray = []
u_ray = []
while t <= 0.9:
u=t*p
u_ray.append(u)
t=t+dt
p=p+dp
print(u_ray)
【问题讨论】:
-
您在每次迭代中再次声明
u_ray,丢失所有先前的值。尝试将u_ray声明放在while之前。还有为什么你需要变量p_ray和t_ray? -
是的,对不起,我是 python 新手。感谢您的帮助!
标签: python loops iteration multiplication