2015-01-20 15 views
3

我的工作創造一個easygui/Python的計算器數學程序,我不斷收到此錯誤爲什麼我在編輯全局變量時出現Type錯誤?

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

我想不通爲什麼它正在發生。我相信這是全球變量我嘗試調用和更改,但我無法弄清楚如何停止錯誤。我知道我的代碼現在有點亂,現在我正在嘗試一個概念驗證。

#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

您不應該有一個名爲'MathType'的變量同時具有相同名稱的函數。 – 2015-01-20 23:56:32

回答

3

4行你有MathType = "Addition"
在第18行,你有def MathType():

錯誤告訴你,它不能稱之爲一個字符串。
MathType()實際上是MathType = "Addition"這是一個字符串,而不是一個函數。

請儘量避免使用相同的名稱爲您的函數,變量等

+0

謝謝。我知道我在做一些愚蠢的事情。我只是無法弄清楚>。< – 2015-01-21 01:38:22

1

有兩類「的MathType」的,一個是字符串,另一個是功能。

0

您有一個函數和一個名爲MathType的字符串變量。

相關問題