
temp=[] def islegalIP(s): lst=s.split(".") for i in lst: if i.startswith("0")==True: #防止输入001.002.003.004情况 return "No" temp.append(int(i)) if len(temp)==4: for j in temp: if j>0 and j<256: return "Yes" else: return "No" else: return "No" s=input('请输入IP地址:') print(islegalIP(s))
下载判断ip地址是否合法用户还喜欢


评论