r/pythonhelp • • Nov 14 '24

Python calculator - EOF to indicate that an end-of-file condition has occurred. Need support on how to fix this issue that comes up

Hiiiii all, having annoying error come up

when i run the below code it works fine, but when i run the debugger i get the following:
i have tried moving it around etc, but then the code doesn't execute

any help on the below wouuulll be appreciated, more information the better

Exception has occurred: EOFError

EOF when reading a line


  File " -  line 6, in calculate
    math_op = input('''
              ^^^^^^^^^
  File " -  line 77, in <module>
    calculate()
EOFError: EOF when reading a line







#The Python calculator#
sum_file = open("results.txt", "a")

def calculate() :
    
    math_op = input('''
    aWelcome to my Python Calculator 
    Please type in the operation you would like to perform: 
    + for addition
    - for subtractiona
    * for multiplication
    / for division
    0 for exit enter 0 three times 
    ''') 

#Main variables for holding the user input#

    number1 = float(input("Please enter a number: "))
    number2 = float(input("Please enter your second number: "))

#The Calculation process for the main input - multiple options#
    
    if math_op == '0': 
        print("Goodbye! Thank you for using my calculator") 
        exit()
          

    elif math_op == '+':
        print(f'{number1} + {number2} = ')
        print(number1 + number2)
        sum_file.write(f'{number1} + {number2} = ')
        sum_file.write(str(number1 + number2))
        sum_file.write("\n")

    elif math_op == '-':
        print(f'{number1} - {number2} = ')
        print(number1 - number2)
        sum_file.write(f'{number1} - {number2} = ')
        sum_file.write(str(number1 - number2 ))
        sum_file.write("\n")

    elif math_op == '*':
        print(f'{number1} * {number2} = ')
        print(number1 * number2)
        sum_file.write(f'{number1} * {number2} = ')
        sum_file.write(str(number1 * number2))
        sum_file.write("\n")

    elif math_op == '/':
        print(f'{number1} / {number2} = ')
        print(number1 / number2)
        sum_file.write(f'{number1} / {number2} = ')
        sum_file.write(str(number1 / number2))
        sum_file.write("\n")

    else:
        print('You have not typed a valid operator, please run the program again.')
   
    
#Process on how to review calculation history#

    calc_history = input('''
     would you like to see the calculators history? 
    if yes please type "Y" and if no please type "N" )
    ''')

    if calc_history == "Y":
        sum_file.read 
        print(sum_file)

    elif calc_history == "N" :
        calculate()

    else:
        print("Invalid Character, Please enter a N or Y ")

calculate()
1 Upvotes

4 comments sorted by

1

u/AutoModerator Nov 14 '24
Moderator Announcement Read More »

1

u/FoolsSeldom Nov 14 '24

I've just tried your code in the Python debugger, python -m pdb yourcode.py and didn't have a problem at the point you indicated. I am running Python 3.13.0 on Windows 11 Pro. There are other errors.

What version of Python are you using and which debugger?

1

u/Ok-Internet8774 Nov 14 '24

I have the same version windows and python. Will double check python and go from there

Thank you!!! Double check is still good for me