Ejemplo n.º 1
0
def sector_area():
    r = enput("Radius: ", float)
    t = enput("Radians or Degrees: ", str).lower()
    if t[0] == "r":
        print("Sector Area is\n%f" % ((r**2 * __promptt(t)) / 2))
    else:
        print("Sector Area is\n%f" % (pi * (r**2) * (__promptt(t) / 360)))
Ejemplo n.º 2
0
def inf():
    operators = [1, -1]
    n = enput("Number of Vectors: ", int)
    t = enput("Type of Vector: ", str).lower()
    o = operators["+-".index(enput("Addition (+)\nor Subtraction (-): ", str))]
    i = 0
    s = [0, 0, 0]
    d = 0
    m = []
    if t[0] == "u" or t[0] == "v":
        while i < n:
            m.append(__enter_vector("Enter Vector"))
            d = len(m[i])
            s[0] += m[i][0] * (o if i != 0 else 1)
            s[1] += m[i][1] * (o if i != 0 else 1)
            s[2] += (m[i][2] * (o if i != 0 else 1) if len(m[i]) > 2 else 0)
            i += 1
    elif t[0] == "p":
        d = 2
        while i < n:
            m = enput("Enter Magnitude: ", float)
            a = radians(__prompta("Enter Angle in Degrees: "))
            s[0] += (m * cos(a)) * (o if i != 0 else 1)
            s[1] += (m * sin(a)) * (o if i != 0 else 1)
            i += 1
    else:
        print("Incorrect Vector Type")
    print(
        "Resultant Vector:\n%s\nResultant Magnitude:\n%f\nResultant Angle:\n%s"
        % (__printv(s), __find_mag(s), __give_angles(s[0], s[1], s[2], d)))
Ejemplo n.º 3
0
def arc_length():
    r = enput("Radius: ", float)
    t = enput("Radians or Degrees: ", str).lower()
    if t[0] == "r":
        print("Arc length of the Circle is\n%f" % (r * __promptt(t)))
    else:
        print("Arc Length of the Circle is\n%f" % (2 * pi * r *
                                                   (__promptt(t) / 360)))
Ejemplo n.º 4
0
def chord():
    r = enput("Radius: ", float)
    t = enput("Radians or Degrees: ", str).lower()
    if t[0] == "r":
        print("Chord Length of the Circle is\n%f" %
              (2 * r * sin(__promptt(t) / 2)))
    else:
        print("Chord Length of the Circle is\n%f" %
              (2 * r * sin(radians(__promptt(t)) / 2)))
Ejemplo n.º 5
0
def __enter_mag_and_angle():
    angle = enput("enter angle: ", float)
    if angle - 0.01 >= 2 * pi or angle + 0.01 <= -2 * pi: # comparing floats with an accuracy of 0.01
        angle = radians(angle)
        print("assuming degrees")
    else:
        print("assuming radians")

    mag = enput("enter magnitude: ", float)

    return [mag * cos(angle), mag * sin(angle)]
def conv():
    s = enput("Converting from: ", str).lower()
    t = enput("To: ", str).lower()
    if s[0] == "p" and (t[0] == "u" or t[0] == "v"):
        m = enput("Magnitude: ", float)
        a = __prompta("Angle in Degrees: ")
        print("<%fi %fj>" % (m * cos(radians(a)), m * sin(radians(a))))
    if (s[0] == "v" or s[0] == "u") and t[0] == "p":
        x = enput("x=", float)
        y = enput("y=", float)
        a = atan2(y, x)
        M = y / sin(a) if x == 0 else x / cos(a)
        print("Magnitude=%f\nAngle=%f" % (M, degrees(a)))
Ejemplo n.º 7
0
def __promptt(z):
    if z.lower()[0] == "d":
        a = enput("Enter Angle in Degrees: ", str)
        angles = {
            "N": 90,
            "S": 270,
            "E": 0,
            "W": 180,
            "NE": 45,
            "SE": 315,
            "NW": 135,
            "SW": 225
        }
        try:
            return angles[a.upper()]
        finally:
            return float(a)
    else:
        return enput("Enter in Radians: ", float)
Ejemplo n.º 8
0
def __combine_com(dense=False):
    num_objs = enput("how many objects? ", int)
    objs_coords = []
    objs_mass = []
    objs_dense = []

    for i in range(0, num_objs):
        coords = enput_list("coordinates of object: ", float)
        mass = enput("mass of object: ", float)
        objs_coords.append(coords)
        objs_mass.append(mass)

    for coord_place in range(0, len(objs_coords[0])):
        cm = 0
        total_mass = 0
        for obj_place in range(0, len(objs_coords)):
            cm += objs_mass[obj_place] * objs_coords[obj_place][coord_place]
            total_mass += objs_mass[obj_place]
        cm /= total_mass
        print("cm: " + str(cm))
def __prompta(o):
    a = enput(o, str)
    angles = {
        "N": 90,
        "S": 270,
        "E": 0,
        "W": 180,
        "NE": 45,
        "NW": 135,
        "SE": 315,
        "SW": 225
    }
    try:
        return float(angles[a.upper()])
    except:
        return float(a)
Ejemplo n.º 10
0
def work_from_velocity():
    vf = enput("vf (m/s): ", float)
    vi = enput("vi (m/s): ", float)
    m = enput("mass (kg): ", float)

    print("W = " + str((m / 2) * (vf**2 - vi**2)))
Ejemplo n.º 11
0
def work_from_distance():
    kx = enput("kx: ", float)
    xi = enput("xi (m): ", float)
    xf = enput("xf (m): ", float)

    print("W = " + str((kx / 2) * (xi**2 - xf**2)))
Ejemplo n.º 12
0
def circumference():
    r = enput("Radius: ", float)
    print("Circumference of the Circle is\n%f" % (2 * pi * r))
Ejemplo n.º 13
0
def area():
    r = enput("Radius: ", float)
    print("Area of the Circle is\n%f" % (pi * r**2))
Ejemplo n.º 14
0
def __enter_matrix():
    matrix = []
    for _ in range(enput("number of rows: ", int)):
        matrix.append(enput_list("enter row: ", float))
    return matrix