while True:
try:
temp=input().strip().split(".")
if str.isalpha(temp[0]) or str.isalpha(temp[1]) or str.isalpha(temp[2]) or str.isalpha(temp[3]):
print("N")
continue
arr=list(map(int,temp))
if 0<=arr[0]<=255 and 0<=arr[1]<=255 and 0<=arr[2]<=255 and 0<=arr[3]<=255:
print("Y")
else:
print("N")
except:
break
注意用python解题不考虑结束代码也可以通过
while True:
arr=list(input().strip().split("."))
try:
if 0<=int(arr[0])<=255 and 0<=int(arr[1])<=255 and 0<=int(arr[2])<=255 and 0<=int(arr[3])<=255:
print("Y")
else:
print("N")
except:
print("N")