首页 > 解决方案 > 如何去特定的线路再次检查条件?

问题描述

if net.res_bus.vm_pu[self.bus]  > 1.005 :
                     self.p_mw = self.p_mw + self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)
                     self.soc_percent += ((self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)*15/60)/self.max_e_mwh) * 100

我在 Python 中使用 pandapower 包。在这里,我需要检查一个条件,如果它是真的,我需要执行一些计算,在完成计算后我需要再次检查它,这应该一直持续到它是真的。所以,这里我需要在计算后再次进入 if 条件。我怎样才能做到这一点?我试过for循环,它在某个地方搞砸了。

标签: pythonconditional-statements

解决方案


您正在寻找一个 pythonwhile循环。

您可以像这样构造您的代码,将 替换ifwhile

while net.res_bus.vm_pu[self.bus] > 1.005 :
    self.p_mw = self.p_mw + self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)
    self.soc_percent += ((self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)*15/60)/self.max_e_mwh) * 100

如果没有更好地理解您的代码,我看不到任何地方的值发生了net.res_bus.vm_pu[self.bus]变化。如果是这种情况,您可能需要检查while


推荐阅读