Python syntax error while taking an IP address as an input

后端 未结 2 1876
萌比男神i
萌比男神i 2021-01-29 16:31

I have a text file called sample_ips.txt containing some random IP addresses as follows:-

182.0.0.15
182.0.0.16
182.0.0.17

I am giving an IP ad

2条回答
  •  灰色年华
    2021-01-29 16:40

    Well, this works:

    input = raw_input("Enter IP:")
    ip = open("sample_ips.txt", "r")
    data = ip.readlines()
    for ips in data:
        ips = ips.strip("\n")
        if input in ips:
            print "true"
        else:
            print "false"
    

    Working for me

    :edit:

    Python3 version

    input = input("Enter IP:")
    ip = open("sample_ips.txt", "r")
    data = ip.readlines()
    for ips in data:
        ips = ips.strip("\n")
        if input in ips:
            print ("true")
        else:
            print ("false")
    

提交回复
热议问题