free friday 1/16/2026

I’ve worked on a long boring essay about Ken Mcwhatever. thats one of the things that i worked on, i also worked on a paper about calculating slope for my math class.

for your class:

import re
 
def to_fraction(n):
    s = str(n)
 
    if "." not in s:
        return s
 
    whole, dec = s.split(".")
    denom = 10 ** len(dec)
    num = int(whole) * denom + int(dec)
 
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
 
    g = gcd(num, denom)
    num //= g
    denom //= g
 
    return str(num) + "/" + str(denom)
 
 
def format_number(n):
    return to_fraction(n)
 
def parse_slope(line):
    cleaned = line.replace(" ", "")
    match = re.search(r"y=\(?(-?\d+/?\d*)\)?x", cleaned)
    if not match:
        return None
    slope_str = match.group(1)
    if "/" in slope_str:
        num, den = map(int, slope_str.split("/"))
        return num / den
    return float(slope_str)

 
def parallel_line_steps(point, slope):
    x1, y1 = point
    m = slope
 
    steps = []
    steps.append("1. Use point-slope form:")
    steps.append("   y - y1 = m(x - x1)")
 
    steps.append("\n2. Substitute the point ({}, {}) and slope m = {}:".format(
        x1, y1, format_number(m)
    ))
    steps.append("   y - {} = {}(x - {})".format(
        y1, format_number(m), x1
    ))
 
    distributed = m * (-x1)
    steps.append("\n3. Distribute the slope:")
    steps.append("   y - {} = {}x + {}".format(
        y1, format_number(m), format_number(distributed)
    ))
 
    b = y1 - m * x1
    steps.append("\n4. Add {} to both sides to isolate y:".format(y1))
    steps.append("   y = {}x + {}".format(
        format_number(m), format_number(b)
    ))
 
    steps.append("\nFinal equation of the parallel line:")
    steps.append("   y = {}x + {}".format(
        format_number(m), format_number(b)
    ))
 
    return "\n".join(steps)
 
 
# -------------------------
# Two-point line steps
# -------------------------
 
def two_point_line_steps(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
 
    steps = []
    steps.append("1. Use the slope formula:")
    steps.append("   m = (y2 - y1) / (x2 - x1)")
 
    if x2 == x1:
        return "This is a vertical line: x = {}".format(x1)
 
    m = (y2 - y1) / (x2 - x1)
 
    steps.append("\n2. Substitute the points ({}, {}) and ({}, {}):".format(
        x1, y1, x2, y2
    ))
    steps.append("   m = ({} - {}) / ({} - {}) = {}".format(
        y2, y1, x2, x1, format_number(m)
    ))
 
    b = y1 - m * x1
 
    steps.append("\n3. Plug slope and one point into y = mx + b:")
    steps.append("   {} = {}({}) + b".format(
        y1, format_number(m), x1
    ))
 
    steps.append("\n4. Solve for b:")
    steps.append("   b = {}".format(format_number(b)))
 
    steps.append("\nFinal equation of the line:")
    steps.append("   y = {}x + {}".format(
        format_number(m), format_number(b)
    ))
 
    return "\n".join(steps)
 
 
# -------------------------
# Menu
def menu():
    print("\nMath Line Calculator")
    print("--------------------")
    print("1. Parallel line through a point")
    print("2. Line through two points")
    print("3. Exit")
    return input("Choose an option (1-3): ")
 
choice = menu()
 
if choice == "1":
    print("\n--- Parallel Line Mode ---")
    x = float(input("Enter x-coordinate of the point: "))
    y = float(input("Enter y-coordinate of the point: "))
    line = input("Enter the line equation (example: y = (-1/2)x + 6): ")
 
    slope = parse_slope(line)
    if slope is None:
        print("\nThat equation does not have a slope.")
    else:
        print("\nWorking it out...\n")
        print(parallel_line_steps((x, y), slope))
 
elif choice == "2":
    print("\n--- Two-Point Line Mode ---")
    x1 = float(input("Enter x1: "))
    y1 = float(input("Enter y1: "))
    x2 = float(input("Enter x2: "))
    y2 = float(input("Enter y2: "))
 
    print("\nWorking it out...\n")
    print(two_point_line_steps((x1, y1), (x2, y2)))
 
elif choice == "3":
    print("\nGoodbye!")
 
elif choice == "67":
    print("\nbro what")
 
else:
    print("\nInvalid choice.")

it’s an old thing ive been having fun with,

it can calculate slope. i finished it today, i attempted to make it write the exact steps but i got lazy.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top