from ipaddress import * net = ( '112.160.0.0 / 255.240.0.0' , 0) n = 0 for ip in net: ip_bin = bin (int(ip)) [2:] n += 1 print (n)
Standard input is empty
from ipaddress import * net = ( '112.160.0.0 / 255.240.0.0' , 0) n = 0 for ip in net: ip_bin = bin (int(ip)) [2:] if ip_bin.count('1') % 3 != 0: n += 1 print (n)