现在,我把它修好。它显示正确的输出。唯一的问题是,它的输出有大括号和引号的每个字符串索引,因为它仍然是一个字符串。如何从输出中删除大括号?在python中有这样的命令吗
networkAddress = raw_input('Enter network address: ')
n = input('Enter number of network bits: ')
h = 32-n
hostAddressOut = 2**h
hostAddress = 0
x = input('Enter number of subnets: ')
octet = networkAddress.split('.')
for i in range(x):
if hostAddress > 255:
hostAddress = 0
thirdOctet = int(octet[2])+1
octet[2] = str(thirdOctet)
octet[3] = str(hostAddress)
print 'subnet', i, ' = ', octet
hostAddress = hostAddressOut
else:
octet[3] = str(hostAddress)
print 'subnet', i, ' = ', octet
hostAddress = hostAddress + hostAddressOut
下面是示例输出。 enter image description here
它不显示任何输出,因为您的最终
if
是:这个条件总是返回
false
,因此不打印任何内容此外,这里:
您正在检查
i == '.'
,然后执行int(i)
。这将始终引发错误,因为无法将“.”转换为int
相关问题 更多 >
编程相关推荐