首页 > 解决方案 > 在函数内添加两个while循环

问题描述

下面是当前代码的摘要,我正在尝试将 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)

标签: pythonpandasfunctionwhile-loop

解决方案


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

第一个执行的while循环是

while weight1 >=0.05:
    weight1-=0.05

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


推荐阅读