我的python代码有问题

时间:2016-03-05 10:12:51

标签: python-2.7

我似乎无法弄清楚这段代码有什么问题。我是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)

  • 括号用于在python中调用函数或更改运算符的优先级,在常量浮点数变为intint之后,添加()并不意味着
  • 如果要在字符串中输出变量,则应使用%sign,如下所示,或者可以使用逗号分隔字符串和变量,如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