2012-09-22 59 views
0

這是我所做的所有編碼,但我不斷收到此語法錯誤。這將在底部解釋更多。如何解決此語法錯誤?我很困惑

def main(): 
    ActualValue() 
    AssessedValue() 
    printResult() 

def ActualValue() 
    global actual_value 
    actual_value = float(input("Enter actual value:\t")) 

def AssessedValue() 
    global assessed_value 
    global property_tax 
    assessed_value = 0.6 * actual_value 
    property_tax = assessed_value/100 * 0.64 

def printResult(): 
    print "n\For a property valued at $", actual_value 
    print "The assessed value is $", assessed_value 
    print "The property tax is $", property_tax 

actual_value = None 
assessed_value = None 
property_tax = None 

main() 

這是我的代碼:

它口口聲聲說我有一個語法錯誤:

def printResult(): 
    print "n\For a property valued at $", actual_value 
    print "The assessed value is $", assessed_value 
    print "The property tax is $", property_tax 
+3

請在您的文章在整個實際的錯誤信息。你也使用Python 2或3? – BrenBarn

+0

這是Python 2.7還是3? – Rapptz

+0

我正在使用pythong 3. –

回答

5

你有\n轉義序列倒退。

另外,您需要確保您的所有函數定義在行尾都有一個冒號。

此外,print在Python 3

1

print一個函數在Python 3的功能:

def printResult(): 
    print("\nFor a property valued at $", actual_value) 
    print("The assessed value is $", assessed_value) 
    print("The property tax is $", property_tax) 

我定你的\n換行轉義代碼你。

你可能想使用.format() method格式化你的輸出:

def printResult(): 
    print("\nFor a property valued at ${0}".format(actual_value)) 
    print("The assessed value is ${0}".format(assessed_value)) 
    print("The property tax is ${0}".format(property_tax)) 
0

只是爲了澄清什麼白金天青說。

def main(): 
    actualValue() 
    assessedValue() 
    printResult() 

def actualValue(): 
    global actual_value 
    actual_value = float(input("Enter actual value:\t")) 

def assessedValue(): 
    global assessed_value 
    global property_tax 
    assessed_value = 0.6 * actual_value 
    property_tax = assessed_value/100 * 0.64 

def printResult(): 
    print "\nFor a property valued at $", actual_value 
    print "The assessed value is $", assessed_value 
    print "The property tax is $", property_tax 

actual_value = None 
assessed_value = None 
property_tax = None 

main() 

這應該工作

+1

它也很適合使用標準語言變量名稱大小寫。在Python中,ActualValue是類名,方法應該是actualValue或更好的actual_value –