【问题标题】:adding two while loops inside a function在函数内添加两个while循环
【发布时间】:2019-12-13 11:20:07
【问题描述】:

下面是当前代码的摘要,我正在尝试将 weight1 和 weight2 的所有值作为一个循环来测试以在函数内部使用,但我得到的结果不正确,请各位大神指教,谢谢

weight1 = 0.95
weight2 = 0.05
while weight1 >= 0.05:
    weight1 -= 0.05
while weight2 <= 0.95:
    weight2 += 0.05


def mod(dates):
    df1['score'] = ((df1['EY_rank'] * weight1) + (df1['ROIC_rank'] * weight2)) / 2
    print(result)
    for i in dates:
        mod(i)

【问题讨论】:

  • 您的代码中有def mod(dates):。这向我表明,您的问题中的缩进不正确。你能解决这个问题吗?

标签: python pandas function while-loop


【解决方案1】:

意图在 Python 中非常重要,因为它是定义语句块的方式。

第一个执行的while循环是

while weight1 >=0.05:
    weight1-=0.05

最后在下一个 while 循环中使用 weight1=0.05

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 2015-05-10
    • 2018-03-16
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2019-03-08
    相关资源
    最近更新 更多