1 def calculate(m,n): 2 ans = [] 3 a = m.split('.',3) 4 b = n.split('.', 3) 5 ip = list(map(int,a)) 6 mask = list(map(int, b)) 7 for i in range(4): 8 x = ip[i] & mask[i] 9 ans.append(x) 10 print("%d.%d.%d.%d" %(ans[0],ans[1],ans[2],ans[3])) 11 def func(): 12 while True: 13 #EOFError的作用就是执行到文件末尾然后抛出异常 14 #try...except捕捉到异常然后执行break语句终止循环 15 try: 16 a = input() 17 a = a.split() 18 m = a[0] 19 n = a[1] 20 calculate(m, n) 21 except EOFError: 22 break 23 24 25 if __name__ == '__main__': 26 func()
标签:__,int,.%,网络地址,split,计算,ans,Problem From: https://www.cnblogs.com/hangsingplus/p/17349977.html