题解 | #合法IP#
合法IP
http://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
其实嘛,一个个去判断就可以了
对于不满足的条件直接打印退出就可以了
正常循环结束即是合法的IP
def ipp(ip): a = ip.split('.') if len(a) != 4 : print('NO') else: for i in a : if not i: print('NO') break elif not i.isnumeric(): print('NO') break elif len(i) > 1 and i[0] == '0': print('NO') break elif int(i) >= 255: print('NO') break else: print('YES') ip = input().strip() ipp(ip)