1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Getting an EOF Error when I run a file that worked fine previously

Discussão em 'Python' iniciado por Stack, Setembro 12, 2025.

  1. Stack

    Stack Membro Participativo

    This is a completed personal project of a simple calculator, and it was working fine the last time I used it in VS Code. But I revisited the code today and this EOF error popped up in the terminal.

    How do I solve this?

    Here's the code

    def solver():
    while True:
    print("\nSelect Operation")
    print("1.Arithmetic Operations")
    print("2.Linear Equation")
    print("3.Quadratic Equation", "\n")

    choice = input("Please enter choice(1/2/3): ")
    if choice == "1":
    try:
    arg1 = float(input("Add 1st number: "))
    arg2 = float(input("Add 2nd number: "))
    except ValueError:
    print("Invalid input. Please enter a number")
    continue

    allowed_functions = set(["+", "-", "/", "*"])

    function = input("Please choose operation from [+, -, *, /]: ")

    if function not in allowed_functions:
    print("Function must contain mathetmatical operation values only")
    continue

    # define mathematical operations
    if function == "+":
    output = arg1 + arg2
    elif function == "-":
    output = arg1 - arg2
    elif function == "*":
    output = arg1 * arg2
    elif function == "/":
    if arg2 == 0:
    print("Division by 0 not possible")
    continue
    output = arg1 / arg2

    str_arg1 = str(arg1)
    str_arg2 = str(arg2)
    str_output = str(output)

    width = max(len(str_arg1), len(str_arg2), len(str_output)) + 2
    top = str_arg1.rjust(width)
    bottom = function + str_arg2.rjust(width - 1)
    lines = "-" * width
    result = str_output.rjust(width)

    problems = f"{top}\n{bottom}\n{lines}\n{result}"
    print(problems)

    quit_program = input("Quit program? (Y/N): ")

    if quit_program.lower() == "y":
    break

    # linear eq
    if choice == "2":
    print(f'\n{"Linear Equation Form:":^24}\n{"ax + b = 0":^24}\n')

    # coefficent inputs
    a = int(input("Please enter a: "))
    if a == 0:
    print("Highest degree coefficent cannot be 0")
    continue

    b = int(input("Please enter b: "))

    # display in equation form
    lin_eq = f"{a:+}x {b:+} = 0"
    final_lin = re.sub(r"(?<!\d)1(?=x)", "", lin_eq.strip("+"))
    aligned_final_lin = f"{final_lin:^24}"
    result = "\n" + aligned_final_lin
    print(result)

    # solving for x
    x = -b / a
    ans_str = f'{f"x = {x}":^24}'
    solved_lin = f'\n{"Solution":^24}\n{ans_str}\n'
    print(solved_lin)

    quit_program = input("Quit program? (Y/N): ")

    if quit_program.lower() == "y":
    break

    # quadratic eq
    if choice == "3":
    print(f'\n{"Quadratic Equation Form":^24}\n{"ax^2 + bx + c = 0":^24}\n')

    a = int(input("Please enter a: "))
    if a == 0 or a == "0":
    print("Highest degree coefficent cannot be 0")
    continue

    b = int(input("Please enter b: "))

    c = int(input("Please enter c: "))

    # display eq
    if b == 0:
    quadr_eq = f"{a:+}x^2 {c:+} = 0"
    final_quadr = re.sub(r"(?<!\d)1(?=x)", "", quadr_eq.strip("+"))
    aligned_final_quadr = f"{final_quadr:^24}"
    result = "\n" + final_quadr

    else:
    quadr_eq = f"{a:+}x^2 {b:+}x {c:+} = 0"
    final_quadr = re.sub(r"(?<!\d)1(?=x)", "", quadr_eq.strip("+"))
    aligned_final_quadr = f"{final_quadr:^24}"
    result = "\n" + aligned_final_quadr

    print(result)

    delta = b**2 - 4 * a * c

    # solve formula

    # defining discriminants
    ans_string = ""

    if delta > 0:
    x1 = (-b + math.sqrt(delta)) / (2 * a)
    x2 = (-b - math.sqrt(delta)) / (2 * a)
    ans = [x1, x2]
    ans_format = f"\n{str(ans):^24}"
    ans_string += (
    f'{"Two real and distinct solutions: " f"{ans_format}":^24}'
    )

    elif delta == 0:
    x1 = (-b + math.sqrt(delta)) / (2 * a)
    x2 = (-b - math.sqrt(delta)) / (2 * a)
    ans = [x1]
    ans_format = f"\n{str(ans):^24}"
    ans_string += f'{"One real solution: " f"{ans_format}":^24}'

    elif delta:
    ans_string += f'{"No real solution":^24}'

    solved_quadr = f'\n{"Solution":^24}\n{ans_string}\n'
    print(solved_quadr)

    quit_program = input("Quit program? (Y/N): ")

    if quit_program.lower() == "y":
    break


    def main():
    solver()


    if __name__ == "__main__":
    main()


    Here's the error:

    Traceback (most recent call last):

    File "c:\Users\Downloads\python\Simple Calc Project\solver.py", line 158, in <module>
    main()

    File "c:\Users\Downloads\python\Simple Calc Project\solver.py", line 154, in main
    solver()

    File "c:\Users\Downloads\python\Simple Calc Project\solver.py", line 12, in solver
    choice = input("Please enter choice(1/2/3): ")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    EOFError: EOF when reading a line

    Continue reading...

Compartilhe esta Página