Exemple #1
0
def gPotential():
    print("Gravitational Potential")

    m1 = input("Mass of the first object m1> ")
    if mPlanet(m1) is False:
        try:
            m1 = float(m1)
        except ValueError:
            m1 = numeric(m1)
    else:
        m1 = mPlanet(m1)

    m2 = input("Mass of the second object m2> ")
    if mPlanet(m2) is False:
        try:
            m2 = float(m2)
        except ValueError:
            m2 = numeric(m2)
    else:
        m2 = mPlanet(m2)

    r = input("Distance between two objects> ")
    try:
        r = float(r)
    except ValueError:
        r = numeric(r)

    U = G * m1 * m2 / (r)
    print("gravitational potential energy  U =", U)

    log_str = "gravitational potential energy  U =" + str(U)
    logger(log_str)

    pause()
    return U
Exemple #2
0
def gForce():
    print("Gravitational Force")

    m1 = input("Mass of the first object m1> ")
    if mPlanet(m1) is False:
        try:
            m1 = float(m1)
        except ValueError:
            m1 = numeric(m1)
    else:
        m1 = mPlanet(m1)

    m2 = input("Mass of the second object m2> ")
    if mPlanet(m2) is False:
        try:
            m2 = float(m2)
        except ValueError:
            m2 = numeric(m2)
    else:
        m2 = mPlanet(m2)

    r = input("Distance between two objects> ")
    try:
        r = float(r)
    except ValueError:
        r = numeric(r)

    F = G * m1 * m2 / (r * r)
    print("Force of gravity F=", F)

    log_str = "Force of gravity F=", str(F)
    logger(log_str)

    pause()
    return F
def parallelCapacitors():
    num_C = input("Number of series capacitors> ")
    try:
        num_C = int(num_C)
    except ValueError:
        print("Please enter an integer value.")
        parallelCapacitors()

    C_eq = 0
    for x in range(num_C):
        print("Enter the capacitance value of capacitor [", x + 1, "]")
        C_n = input("> ")
        try:
            C_n = float(C_n)
        except ValueError:
            C_n = numeric(C_n)
        C_eq += C_n

    print("Equivalent capacitance C = ", C_eq)

    log_str = "Equivalent capacitance C = " + str(C_eq)
    logger(log_str)

    pause()
    return C_eq
def seriesResistors():
    num_R = input("Number of series resistors> ")
    try:
        num_R = int(num_R)
    except ValueError:
        print("Please enter an integer value.")
        seriesResistors()

    R_eq = 0
    for x in range(num_R):
        print("Enter the resistance value of Resistor [", x + 1, "]")
        R_n = input("> ")
        try:
            R_n = float(R_n)
        except ValueError:
            R_n = numeric(R_n)
        R_eq += R_n

    print("Equivalent resistance R = ", R_eq)

    log_str = "Equivalent resistance R = " + str(R_eq)
    logger(log_str)

    pause()
    return R_eq
def seriesInductors():
    num_L = input("Number of series inductors> ")
    try:
        num_L = int(num_L)
    except ValueError:
        print("Please enter an integer value.")
        seriesInductors()

    L_eq = 0
    for x in range(num_L):
        print("Enter the capacitance value of inductors [", x + 1, "]")
        L_n = input("> ")
        try:
            L_n = float(L_n)
        except ValueError:
            L_n = numeric(L_n)
        L_eq += L_n

    print("Equivalent inductance L = ", L_eq)

    log_str = "Equivalent inductance L = " + str(L_eq)
    logger(log_str)

    pause()
    return L_eq
Exemple #6
0
 def var_filler():
     for i in range(len(var_list)):
         print("Enter a value for ", var_list[i][1])
         var_list[i][0] = input("> ")
         try:
             var_list[i][0] = float(var_list[i][0])
         except ValueError:
             var_list[i][0] = numeric(var_list[i][0])
Exemple #7
0
def transition():
    print("Photoelectric Effect")

    n_i = input("Initial orbit number ni> ")
    try:
        n_i = int(n_i)
    except ValueError:
        n_i = numeric(n_i)

    n_f = input("final orbit number nf> ")
    try:
        n_f = int(n_f)
    except ValueError:
        n_f = numeric(n_f)

    Z = input("Atomic Number of the element> ")
    try:
        Z = int(Z)
    except ValueError:
        Z = numeric(Z)

    i = 1 / (n_i**2)
    f = 2 / (n_f**2)
    wav = R_d * (i - f) * Z**2
    wav = 1 / wav

    print("Transition Wavelength l= ", wav)

    print("EM spectrum:", EMspectrum(wav))

    f = c / wav
    print("Corresponding frequency f =", f)

    E = h * f
    print("Energy of the photon E =", E)

    log_str = "Transition Wavelength l= " + str(wav) + "\n" \
              "                               " + "EM spectrum:" + str(EMspectrum(wav)) + "\n" \
              "                               " + "Corresponding frequency f =" + str(f) + "\n" \
              "                               " + "Energy of the photon E =" + str(E)
    logger(log_str)

    pause()
    return wav
Exemple #8
0
def dragForce():
    print("Drag Force")

    Cd = input("Drag coefficient>")
    if Cd not in Cd_dict:
        try:
            Cd = float(Cd)
        except ValueError:
            Cd = numeric(Cd)
    elif Cd in Cd_dict:
        Cd = Cd_dict[Cd]

    A = input("Frontal surface area> ")
    try:
        A = float(A)
    except ValueError:
        A = numeric(A)

    p = input("Medium density> ")
    try:
        p = float(p)
    except ValueError:
        p = numeric(p)

    v = input("Velocity> ")
    try:
        v = float(v)
    except ValueError:
        v = numeric(v)

    F_d = 0.5 * Cd * p * v * v * A
    print("Drag force Fd = ", F_d)

    log_str = "Drag force Fd = " + str(F_d)
    logger(log_str)

    pause()
    return F_d
Exemple #9
0
def terminalVelocity():
    print("Terminal Velocity")

    m = input("Mass of the object> ")
    try:
        m = float(m)
    except ValueError:
        m = numeric(m)

    Cd = input("Drag coefficient>")
    if Cd not in Cd_dict:
        try:
            Cd = float(Cd)
        except ValueError:
            Cd = numeric(Cd)
    elif Cd in Cd_dict:
        Cd = Cd_dict[Cd]

    A = input("Frontal surface area> ")
    try:
        A = float(A)
    except ValueError:
        A = numeric(A)

    p = input("medium density> ")
    try:
        p = float(p)
    except ValueError:
        p = numeric(p)

    v_term = sqrt((2 * m * a_g) / (Cd * p * A))
    print("Terminal velocity v = ", v_term)

    log_str = "Terminal velocity v = " + str(v_term)
    logger(log_str)

    pause()
    return v_term
Exemple #10
0
def idealGas():
    P = 0
    V = 0
    T = 0
    n = 0
    var_list = [[P, "pressure"], [V, "volume"], [T, "temperature"],
                [n, "moles number"]]
    print("Select a variable to solve for> ")
    print("[1] - pressure (P)")
    print("[2] - volume (V) ")
    print("[3] - temperature (T)")
    print("[4] - number of moles (n)")
    select = input("Enter the number of your selection> ")
    try:
        select = int(select)
    except ValueError:
        select = numeric(select)

    result_name = var_list[select - 1][1]
    del var_list[select - 1]

    def var_filler():
        for i in range(len(var_list)):
            print("Enter a value for ", var_list[i][1])
            var_list[i][0] = input("> ")
            try:
                var_list[i][0] = float(var_list[i][0])
            except ValueError:
                var_list[i][0] = numeric(var_list[i][0])

    if select == 1:
        P = Symbol('P')
        var_filler()
        result = solve(
            var_list[2][0] * R * var_list[1][0] - P * var_list[0][0], P)
    elif select == 2:
        V = Symbol('V')
        var_filler()
        result = solve(
            var_list[2][0] * R * var_list[1][0] - var_list[0][0] * V, V)
    elif select == 3:
        T = Symbol('T')
        var_filler()
        result = solve(
            var_list[2][0] * R * T - var_list[0][0] * var_list[1][0], T)
    elif select == 4:
        n = Symbol('n')
        var_filler()
        result = solve(
            n * R * var_list[2][0] - var_list[0][0] * var_list[1][0], n)
    else:
        print("Please enter a valid selection")
        idealGas()

    print("Value for", result_name, "=", result)

    log_str = "Value for " + str(result_name) + "=" + str(result)
    logger(log_str)

    pause()
    return result