3

I am working on creating an easygui/python calculator math program and i keep getting this error

Traceback (most recent call last):
  File "C:\Python27\Scripts\MathHelper.py", line 83, in <module>
    MathType()
TypeError: 'str' object is not callable

I can't figure out why it is happening. I believe it is with the global variable I try to call and change but i can't figure out how to stop the error. I know my code is kind of messy right now i am trying to work a proof of concept.

#MathType == what kind of math to compute. IE. Subtraction or addition
#Selection == Yes or no
math = 1
MathType = "Addition"
loop = 1
import easygui

def start():
  print("startMessage")
  MathType = easygui.msgbox(msg="Hello and welcome to my Math Helper.",
                 title = "Welcome")
  startMessage = "0"
#End of start
#
#
#

def MathType():
  global MathType
  print("Math Type Gathered")
  MathType = easygui.buttonbox("Select the type of Math you would like to compute:",
                                title = "Math Selection",
                                choices = ["Addition", "Subtraction", "Shut Down"] )
#End of MathType
#
#
#

def Addition():
  num1 = easygui.enterbox(msg = "Please enter the first Number.",
                     title = "Addition")
#print(num1)
  num2 = easygui.enterbox(msg = "Please enter the second number.  "+num1+" + ___ = ___",
                        title = "Addition")
#print(num2)
  easygui.msgbox("Here is your equation:  "+num1+"  +  "+num2+" = ___ ",
                 title = "Equation")
  NUM1 = int(num1)
  NUM2 = int(num2)
  numFinal = (NUM1 + NUM2)
  NUM3 = str(numFinal)

  easygui.msgbox(msg="Your answer is:  "+NUM3+"",
                 title="Final")
#print(numFinal)
#End of Addition
#
#

def Subtraction():
  num1 = easygui.enterbox(msg = "Please enter the first Number.",
                     title = "Subtraction")
#print(num1)
  num2 = easygui.enterbox(msg = "Please enter the second number.  "+num1+" - ___ = ___",
                        title = "Subtraction")
#print(num2)
  easygui.msgbox("Here is your equation:  "+num1+"  -  "+num2+" = ___ ",
               title = "Equation")
  NUM1 = int(num1)
  NUM2 = int(num2)
  numFinal = (NUM1 - NUM2)
  NUM3 = numFinal

  easygui.msgbox(msg="Your answer is:  "+NUM3+"",
               title="Final")
#print(numFinal)
#End of Subtraction
#
#

def MathFinder():
    if MathType == "Addition":
        print("Addition")
        Addition()
    elif MathType == "Subtraction":
        print("Subtraction")
        Subtraction()
    elif MathType == "Shut Down":
        exit()

start()
while loop == 1:
  MathType()
  MathFinder()
  • 1
    You shouldn't have a variable named `MathType` at the same time as having a function of the same name. – Dan D. Jan 20 '15 at 23:56

3 Answers3

3

At line 4 you have MathType = "Addition"
At line 18 you have def MathType():

The error tells you that it can't call a string.
MathType() is actually MathType = "Addition" which is a string and not a function.

Please try to prevent using the same name for your functions, variables etc.

Jordy19
  • 106
  • 2
  • 11
1

You have two types of 'MathType', one is a string and other is a function.

sancospi
  • 21
  • 3
0

You have a function and a string variable named MathType.

Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70