简体   繁体   English

使用 while 循环确定 y 的终值

[英]Determine the terminal value of y using a while loop

Rolling summation.滚动求和。

Determine the terminal value of y .确定y的终值。 While y is less than the threshold, add 0.01*(−2) to the old value of y .y小于阈值时,将0.01*(−2)添加到y的旧值。

y = 0.1 
threshold = .11

I tried this.我试过了。

while  y < threshold:
    if True: 
        print(y+ 0.01*(y-y**2))
    else:
        break

Why did nothing run when i tried this?为什么当我尝试这个时什么也没有运行?

If your intent is to start with y = 0.1 , and then continuously update y by adding the value of 0.01*(yy**2) to the current value of y until it equals or exceeds the value of threshold = 0.11 , the following code accomplishes this.如果您的意图是从y = 0.1开始,然后通过将0.01*(yy**2)的值添加到 y 的当前值来不断更新y直到它等于或超过threshold = 0.11的值,则以下代码完成这个。 If your intent is otherwise, please specify.如果您的意图不是这样,请说明。

y = 0.1
threshold = .11

while y < threshold:
    y += 0.01*(y-y**2)

print(y)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM