我有一个子网程序,用于显示所需主机或网络数量的子网掩码。我的问题是我无法让底部的 else 工作。它一直告诉我它有一个意外的取消缩进,但是当我缩进时它说意外的取消缩进。我该如何解决这个问题,以便它告诉用户唯一接受的输入是“主机”、“网络”或“q”。
while True:
print("-------------------------------------------------------------------")
print("")
print("Welcome to the Basic Information Generator : Automatic Subnet System")
print("")
try:
inquire = raw_input("Are you figuring for HOSTS or NETWORKS? \
('Q' exits') :").lower()
if inquire == 'hosts':
try:
number = int(raw_input("How many HOSTS do you need on the network?"))
if number == 0:
print("[WARNING] Your subnet mask is 255.255.255.254 [WARNING]")
print("This subnet has NO usable hosts...")
if number <= 2 and number > 0:
print("Your subnet mask is 255.255.255.252")
if number <= 6 and number > 2:
print("Your subnet mask is 255.255.255.248")
if number <= 14 and number > 6:
print("Your subnet mask is 255.255.255.240")
if number <= 30 and number > 14:
print("Your subnet mask is 255.255.255.224")
其余部分在 pyscripter 中正确缩进,但不会在此处缩进...
if number <= 62 and number > 30:
print("Your subnet mask is 255.255.255.192")
if number <= 126 and number > 62:
print("Your subnet mask is 255.255.255.128")
if number <= 254 and number > 126:
print("Your subnet mask is 255.255.255.0")
if number <= 510 and number > 254:
print("Your subnet mask is 255.255.254.0")
if number <= 1022 and number > 510:
print("Your subnet mask is 255.255.252.0")
if number <= 2046 and number > 1022:
print("Your subnet mask is 255.255.248.0")
if number <= 4094 and number > 2046:
print("Your subnet mask is 255.255.240.0")
if number <= 8190 and number > 4094:
print("Your subnet mask is 255.255.224.0")
if number <= 16382 and number > 8190:
print("Your subnet mask is 255.255.192.0")
if number <= 32766 and number > 16382:
print("Your subnet mask is 255.255.128.0")
if number <= 65534 and number > 32766:
print("Your subnet mask is 255.255.0.0")
if number <= 131070 and number > 65534:
print("Your subnet mask is 255.254.0.0")
if number <= 262142 and number > 131070:
print("Your subent mask is 255.252.0.0")
if number <= 524286 and number > 262142:
print("Your subnet mask is 255.248.0.0")
if number <= 1048574 and number > 524286:
print("Your subnet mask is 255.240.0.0")
if number <= 2097150 and number > 1048574:
print("Your subnet mask is 255.224.0.0")
if number <= 4194302 and number > 2097150:
print("Your subnet mask is 255.192.0.0")
if number <= 8388606 and number > 4194302:
print("Your subnet mask is 255.128.0.0")
if number <= 16777214 and number > 8388606:
print("Your subnet mask is 255.0.0.0")
if number <= 33554430 and number > 16777214:
print("Your subnet mask is 254.0.0.0")
if number <= 67108862 and number > 33554430:
print("Your subnet mask is 252.0.0.0")
if number <= 134217726 and number > 67108862:
print("Your subnet mask is 248.0.0.0")
if number <= 268435454 and number > 134217726:
print("Your subnet mask is 240.0.0.0")
if number <= 536870910 and number > 268435454:
print("Your subnet mask is 224.0.0.0")
if number <= 1073741822 and number > 536870910:
print("Your subnet mask is 192.0.0.0")
if number <= 2147483646 and number > 1073741822:
print("Your subnet mask is 128.0.0.0")
if number > 2147483646:
print("Invalid Number of Hosts. No such Netmask applicable.")
except:
print("Enter a number between 1 and 2,147,483,646")
elif inquire == 'networks':
number = input("How many SUBNETS do you need on the network?")
if number == 0:
print("[WARNING] Your subnet mask is 0.0.0.0 [WARNING]")
print("This netmask yeilds NO usable subnets...")
if number == 1:
print("Your subnet mask is 255.0.0.0")
if number == 2:
print("Your subnet mask is 255.128.0.0")
if number <= 4 and number > 2:
print("Your subnet mask is 255.192.0.0")
if number <= 8 and number > 4:
print("Your subnet mask is 255.224.0.0")
if number <= 16 and number > 8:
print("Your subnet mask is 255.240.0.0")
if number <= 32 and number > 16:
print("Your subnet mask is 255.248.0.0")
if number <= 64 and number > 32:
print("Your subnet mask is 255.252.0.0")
if number <= 128 and number > 64:
print("Your subnet mask is 255.254.0.0")
if number <= 256 and number > 128:
print("Your subnet mask is 255.255.0.0")
if number <= 512 and number > 256:
print("Your subnet mask is 255.255.128.0")
if number <= 1024 and number > 512:
print("Your subnet mask is 255.255.192.0")
if number <= 2048 and number > 1024:
print("Your subnet mask is 255.255.224.0")
if number <= 4096 and number > 2048:
print("Your subnet mask is 255.255.240.0")
if number <= 8192 and number > 4096:
print("Your subnet mask is 255.255.248.0")
if number <= 16384 and number > 8192:
print("Your subnet mask is 255.255.252.0")
if number <= 32768 and number > 16384:
print("Your subnet mask is 255.255.254.0")
if number <= 65536 and number > 32768:
print("Your subnet mask is 255.255.255.0")
if number <= 131072 and number > 65536:
print("Your subnet mask is 255.255.255.128")
if number <= 262144 and number > 131072:
print("Your subnet mask is 255.255.255.192")
if number <= 524288 and number > 262144:
print("Your subnet mask is 255.255.255.224")
if number <= 1048576 and number > 524288:
print("Your subnet mask is 255.255.255.240")
if number <= 2097152 and number > 1048576:
print("Your subnet mask is 255.255.255.248")
if number <= 4194304 and number > 2097152:
print("Your subnet mask is 255.255.255.252")
elif inquire == 'q':
break
else:
print("NEED CERTAIN THINGS")
“需要某些东西”只是填充代码,所以我会知道“else:”语句有效......