<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def API520_A_g(m, T, Z, MW, k, P1, P2=101325, Kd=0.975, Kb=1, Kc=1):
    r'''Calculates required relief valve area for an API 520 valve passing
    a gas or a vapor, at either critical or sub-critical flow.

    For critical flow:

    .. math::
        A = \frac{m}{CK_dP_1K_bK_c}\sqrt{\frac{TZ}{M}}

    For sub-critical flow:

    .. math::
        A = \frac{17.9m}{F_2K_dK_c}\sqrt{\frac{TZ}{MP_1(P_1-P_2)}}

    Parameters
    ----------
    m : float
        Mass flow rate of vapor through the valve, [kg/s]
    T : float
        Temperature of vapor entering the valve, [K]
    Z : float
        Compressibility factor of the vapor, [-]
    MW : float
        Molecular weight of the vapor, [g/mol]
    k : float
        Isentropic coefficient or ideal gas heat capacity ratio [-]
    P1 : float
        Upstream relieving pressure; the set pressure plus the allowable
        overpressure, plus atmospheric pressure, [Pa]
    P2 : float, optional
        Built-up backpressure; the increase in pressure during flow at the
        outlet of a pressure-relief device after it opens, [Pa]
    Kd : float, optional
        The effective coefficient of discharge, from the manufacturer or for
        preliminary sizing, using 0.975 normally or 0.62 when used with a
        rupture disc as described in [1]_, []
    Kb : float, optional
        Correction due to vapor backpressure [-]
    Kc : float, optional
        Combination correction factor for installation with a ruture disk
        upstream of the PRV, []

    Returns
    -------
    A : float
        Minimum area for relief valve according to [1]_, [m^2]

    Notes
    -----
    Units are interlally kg/hr, kPa, and mm^2 to match [1]_.

    Examples
    --------
    Example 1 from [1]_ for critical flow, matches:

    >>> API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, Kb=1, Kc=1)
    0.0036990460646834414

    Example 2 from [1]_ for sub-critical flow, matches:

    >>> API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, P2=532E3, Kd=0.975, Kb=1, Kc=1)
    0.004248358775943481

    References
    ----------
    .. [1] API Standard 520, Part 1 - Sizing and Selection.
    '''
    P1, P2 = P1/1000., P2/1000. # Pa to Kpa in the standard
    m = m*3600. # kg/s to kg/hr
    if is_critical_flow(P1, P2, k):
        C = API520_C(k)
        A = m/(C*Kd*Kb*Kc*P1)*(T*Z/MW)**0.5
    else:
        F2 = API520_F2(k, P1, P2)
        A = 17.9*m/(F2*Kd*Kc)*(T*Z/(MW*P1*(P1-P2)))**0.5
    return A*0.001**2