python递归关系如何确定循环并逐行打印所有结果

标签 python python-3.x recurrence

各位好心的天才们,我已经尝试解决下面的递推关系,并且真的尽力了。 r 是 float ,它是一个输入值,t 是一个整数,它是时间(秒),s 也是一个输入值( float )。

t(i+1)=rt(i)(1-ti), t1 = input value

我必须打印 t1t2t3t4t5 >, t6~ t(s-1) 逐行

我发现困难的是我无法做出一些正确的确定循环。

d = float(input('density'))
r = float(input('parameter'))
s = int(input('seconds'))
t = int()
print(d)
a = int()
while 2 < a <= s - 1
    a = 2
    return_result = r*d*(1-d)
    print(return_result)
    

最佳答案

1) 循环的语法是以冒号“:”结尾

2) 多重比较必须用“and”或“or”连接

3) 循环的控制变量需要在循环内更新,这样就不会陷入无限循环。

语法更新:

while 2 < a and a <= s - 1:
    #calculations
    a += 1

关于python递归关系如何确定循环并逐行打印所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52430463/

相关文章:

python-3.x - Tkinter 中的多重处理

python - `async for` 的语义 - __anext__ 调用可以重叠吗?

recursion - 如何根据递归关系确定递归树的高度?

python - 带有分类 X 轴的 Matplotlib 带状图 (fill_ Between)

python - python 中的 HEAD 请求无法正常工作

python-3.x - PyQt6: AttributeError: 类型对象 'QImage' 没有属性 'Format_RGB888'

algorithm - 使用递归树方法求解带分数的递归方程

python - 使用 str.split (panda) 拆分一列时强制列数

python - Python 中 ISO 8601 的日期时间

algorithm - 选择排序递归关系