我是 python 编程的新手,在任何地方都找不到这个帮助
我有一个要在指定列表 exp 中搜索的用户输入值:
option=input("option: ")
iplist=['192.168.1.1', '192.168.1.2', '192.168.1.254']
while option <= "3":
#this is wrong. Help!
nub = iplist[option]
subprocess.call(["ping", nub])
我希望用户的选项是该程序列表中的数字,输出应该是:
Option : 0
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=2ms TTL=64
Reply from 192.168.1.1: bytes=32 time=2ms TTL=64
Reply from 192.168.1.1: bytes=32 time=2ms TTL=64
Reply from 192.168.1.1: bytes=32 time=2ms TTL=64
Ping statistics for 192.168.1.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 2ms, Average = 2ms
隔江千里
相关分类