我在用python写作业。我写了几个函数,一切都很好。我尝试添加第三个函数,python给出消息“期望一个缩进块”。我知道混合使用制表符和空格是有问题的。我两个都试过了,没有什么不同。尝试更改制表符间距,在不同的PC上重写整个代码。我一无所知。可能的问题是什么?
def xor_bytes(byte1, byte2):
xor = ""
for i in range(len(byte1)):
if byte1[i] == byte2[i]:
xor = xor + "0"
else:
xor = xor + "1"
return xor
def verify_checksum(datagram):
checksum = '00000000'
total = False
for i in range((len(datagram)/8)-1):
checksum = xor_bytes(checksum,datagram[8*(i):8*(i+1)])
if checksum == datagram[len(datagram)-8 : len(datagram)]:
total = True
return total
def check_datagram(datagram,src_comp,dst_app):发布于 2012-12-12 03:48:17
您可能还在混用制表符和空格,不要这样做。
运行python -tt yourscript.py以检测缩进不一致的位置。将编辑器调整为仅使用空格(将制表符展开为空格,使用空格进行缩进,等等)。
请注意,您确实需要为新函数指定一个主体,否则您将得到相同的错误:
>>> def foo(bar):
...
File "<stdin>", line 2
^
IndentationError: expected an indented block发布于 2013-03-08 02:42:50
在你的例子的最后一行之后有没有什么东西?
def check_datagram(datagram,src_comp,dst_app):如果不是这样: Python要求代码块不能为“空”。我会将其更改为:
def check_datagram(datagram,src_comp,dst_app):
passhttps://stackoverflow.com/questions/13827318
复制相似问题