gpt4 book ai didi

python - 将结果添加到列表并设置 for 循环

转载 作者:太空宇宙 更新时间:2023-11-04 00:25:50 27 4
gpt4 key购买 nike

对于一项学校作业,我正在编写一种算法,该算法使用欧拉方法计算斜率。在其中的一部分,我有一个 for 循环,它将重复方程式的模式,直到满足最终结果。我需要的是一种将每个结果添加到列表中然后绘制列表中每个项目的方法。如果可能的话,我还需要一些帮助来设置 for 循环。

这就是我所拥有的,记住我在编码方面非常缺乏经验(请耐心等待)

stpsz = input ("Define "h" Value (step size)")
tfinal = input ("Define Final "T" Value (stopping place)")
xnow = input ("Define "X0" as a Starting Value")

t = 0
while t > tfinal
t = t + 1
slopenow = (xnow * (1-xnow))

#Save slopenow (as a number, not variable) to a list of slopes ( I don't understand how to make a list like this)
#Save xnow (as a number, not variable) to a list of xs)

xnext = (slopenow * stpsz)+(xnow)
xnext = x now

#repeat while-loop until tfinal is reached)

我非常感谢你们能提供的任何帮助。

最佳答案

听起来您正在寻找的是一个while 循环。像这样:

t = 0
while t < 10:
t = t + 1
# more code here

关于python - 将结果添加到列表并设置 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47494670/

27 4 0
文章推荐: css - 在没有父容器的情况下对齐两个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com