简体   繁体   中英

How to go to a specific line to check the condition again?

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

I am using the pandapower package in Python. Here, I need to check a condition, if it is true I need to perform some calculations and after doing the calculations I need to check it again, and this should go until it is true. So, here I need to go to the if condition again after the calculations. How can I do that? I tried for loop, it is getting messed up somewhere.

You are looking for a python while loop.

You could structure your code like this, replacing the if with a 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

Without understanding your code better, I don't see anywhere that the value of net.res_bus.vm_pu[self.bus] is changed. If that is the case, you may want to check a different variable in the while

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM