2016-03-05 65 views
-3

問題我似乎無法弄清楚這個代碼有什麼問題。我是python的新手,一般編碼。我一直在尋求其他的解決方案,但由於某種原因,我一直在痛苦的循環結束了......我有我的python代碼

x = int(raw_input("Enter the value of the exponent of i.")) 
y = x/float(4) 
z = y-int(y) 
#---------------------- 
if int(z) == 0(): 
    print "The answer is 1." 

if int(z) == 0.25(): 
    print "The answer is i." 

if int(z) == 0.5(): 
    print "The answer is -1." 

if int(z) == 0.75(): 
    print "The answer is -i." 

出於某種原因,我的一切嘗試總是得到這樣的錯誤:

Traceback (most recent call last): 
File "C:\Users\John\Desktop\I_Exp.py", line 6, in <module> 
if int(z) == 0(): 
TypeError: 'int' object is not callable 
+1

那麼你想在這裏打個電話嗎?什麼是用來調用某些東西的語法?這可能是錯誤意味着什麼的線索。 –

+0

()用於調用函數,而0是一個「int」對象。我認爲你應該首先閱讀Python的基本語法。 –

回答

0
  • 括號用於調用python中的運算符或改變運算符的優先級,在浮點數不變的情況下,將int更改爲int後添加()並不意味着加。
  • 當你想輸出字符串中的變量,你應該使用%符號下面,或者你可以用逗號將字符串和變量分離出來,就像print "the answer is", d

你可以這樣做:

x = float(raw_input("Enter the value of the exponent of i.")) 
y = x/4 
z = y-int(y) 

if (z == 0): 
    print "The answer is 1." 

if (z == 0.25): 
    print "The answer is %d." % i 

if (z == 0.5): 
    print "The answer is -1." 

if (z == 0.75): 
    print "The answer is -%d." % i