Power flow balance, active and reactive power , losses in julia

Hi @saeedata7, welcome to the forum.

are these codes right for calculating active and reactive power, losses in Python?

Note that this is a forum for Julia questions. We cannot help you with Python. However, your code looks like Julia, so perhaps this is just a typo?

You can improve your question by reading Please read: make it easier to help you.

I can’t run your code because you are missing the definition of many of your data, etc.

If you’re interested in Power system optimization in Jullia, you may want to checkout GitHub - lanl-ansi/PowerModels.jl: A Julia/JuMP Package for Power Network Optimization.