如何转到特定行再次检查状况?

2024-09-10 15:09:50 发布

您现在位置:Python中文网/ 问答频道 /正文

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条件。我该怎么做?我试过了,它在某个地方搞砸了


Tags: nameselfsourcedatagetnetiftime
1条回答
网友
1楼 · 发布于 2024-09-10 15:09:50

您正在寻找python ^{} loop.

您可以这样构造代码,将if替换为while

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中的另一个变量

相关问题 更多 >