Python错误-缩进错误:意外缩进
看起来在第二个If条件下有一个缩进错误。请一些人看一下,让我知道需要什么修正Python错误-缩进错误:意外缩进,python,Python,看起来在第二个If条件下有一个缩进错误。请一些人看一下,让我知道需要什么修正 IP = raw_input("Enter the Ip Address \n") IPAddress= IP.split('.') if (len(IPAddress) == 4): print " It is a valid IP address " x1,x2,x3,x4 = IP.split('.') if(int(x1) == 192 and (0 <= int(x2) a
IP = raw_input("Enter the Ip Address \n")
IPAddress= IP.split('.')
if (len(IPAddress) == 4):
print " It is a valid IP address "
x1,x2,x3,x4 = IP.split('.')
if(int(x1) == 192 and (0 <= int(x2) and int(x2) <= 255) and (0 <= int(x3) <= 255) and (0 <= int(x4) <= 255)) or (int(x1) == 172 and (16 <= int(x2) <= 31) and (0 <= int(x3) <= 255) and (0 <= int(x4) <= 255)) or (int(x1) == 10 and (0 <= int(x2) <= 255) and (0 <= int(x3) <= 255)and (0 <= int(x4) <= 255)):
print IP + " is a private IP address"
else:
print IP + " is a public IP address"
else:
print IP " is invalid "
IP=raw\u输入(“输入IP地址”)
IPAddress=IP.split('.'))
如果(len(IPAddress)==4):
打印“它是一个有效的IP地址”
x1,x2,x3,x4=中分面('.'))
if(int(x1)=192和(0我将您的代码复制粘贴到一个名为wing ide的程序中,它直接告诉我您的缩进是第二个if语句,else是关闭的
使用这样一个程序来帮助你解决容易犯的错误当有人需要阅读他们的错误状态时,你的缩进在第二条if语句上是关闭的。你为什么要缩进这么多?如果它是要在那里的话,请将它与print
语句对齐。并缩进x1
等变量。记住:a始终在之后缩进:
。至于修复,请删除第二个if
和else
之前的空格。我想程序不会报告x1,x2,x3,x4=IP.split('.'))
缩进不正确,因为它只是报告遇到的第一个缩进错误,然后放弃。或者它不够聪明,没有意识到最终的else:
属于第一个if:
。原则上x1、x2、x3等缩进不正确。de程序将运行该程序,无论if函数是什么我是。当然。要理解x1,x2,
东西缩进错误,你需要理解第二个if…else
部分应该是第一个if
块的一部分,我们只知道这一点,因为我们可以看到第二个else:
,它是(可能)用于匹配第一个if
。我不希望一个简单的代码检查器必须处理这种事情。:)