Exerciseschevron_rightChapter 2chevron_right2.2
fitness_center

Exercise 2.2

Productivity Index

Level 1
Chapter 2: Python Essentials
descriptionProblem

The productivity index (PI, often written as J) measures how efficiently a well converts pressure drawdown into oil flow:

J=qoPePwfJ = \frac{q_o}{P_e - P_{wf}}

where qoq_o is the oil rate (bopd), PeP_e is the average reservoir pressure (psi), and PwfP_{wf} is the flowing bottomhole pressure (psi).

Write productivity_index(oil_rate, reservoir_pressure, flowing_pressure) that:

  1. Validates the inputs. If flowing_pressure >= reservoir_pressure,

flow would be reversed (or zero). That is a non-physical configuration. Raise ValueError instead of returning a meaningless number.

  1. Returns a tuple (J, AOF) where J is the productivity index in

bopd/psi and AOF = J × P_e is the Absolute Open Flow, the theoretical maximum rate if P_wf dropped to zero.

Test with: q_o = 1,200 bopd, P_e = 4,500 psi, P_wf = 2,800 psi.

> Think about it: is the AOF a realistic production target? What > happens to the well, the formation, and the recovery factor if you > actually try to pull P_wf down to zero?

lightbulbHints (0/4)

Stuck? Reveal hints one at a time — they progress from nudge to near-solution.

codeYour solution
main.py
visibilityReveal reference solutionexpand_more

Try solving it yourself first — the hints walk you through it. The solution below is one valid approach; yours may differ and still be correct.

def productivity_index(oil_rate, reservoir_pressure, flowing_pressure):
    if flowing_pressure >= reservoir_pressure:
        raise ValueError(
            f"flowing_pressure ({flowing_pressure} psi) must be below "
            f"reservoir_pressure ({reservoir_pressure} psi)"
        )
    J = oil_rate / (reservoir_pressure - flowing_pressure)
    aof = J * reservoir_pressure
    return J, aof


J, aof = productivity_index(1200, 4500, 2800)
print(f"J   = {J:.4f} bopd/psi")
print(f"AOF = {aof:,.1f} bopd")

lockCopying code is a Full Access feature.