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