给你一个字符串,你怎么判断是不是ip地址?手写这段代码,并写出测试用例
s = input('input ip :').split('.') #输入是一个列表,其中的数字是字符; counter = 0 #负号不是数字,会判定为非正数。isdigit() for i in range(len(s)): # 测试要点1:是正数且第一个数不等于0,后面的数都小于等于255; if s[i].isdigit() == True and int(s[0]) > 0 and int(s[i]) <= 255: counter +=1 else: pass # 测试要点2:长度等于4且满足条件1; if counter == 4 and len(s) == 4: print("input string is IP address") else: print("input string is not a Ip Address")