From 0b00c996f6da48ca026e1c84cb95398adbd1eac8 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 8 Aug 2021 16:40:41 +0530 Subject: [PATCH 1/2] Created check_valid_ip_address.py --- maths/check_valid_ip_address.py | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 maths/check_valid_ip_address.py diff --git a/maths/check_valid_ip_address.py b/maths/check_valid_ip_address.py new file mode 100644 index 000000000000..320d3987c184 --- /dev/null +++ b/maths/check_valid_ip_address.py @@ -0,0 +1,46 @@ +""" +Checking valid Ip Address. +A valid IP address must be in the form of A.B.C.D, +where A,B,C and D are numbers from 0-254 +for example: 192.168.23.1, 172.254.254.254 are valid IP address + 192.168.255.0, 255.192.3.121 are Invalid IP address +""" + + +def check_valid_ip(ip: str) -> bool: + """ + print "Valid IP adddress" If IP is valid. + or + print "Invalid IP address" If IP is Invalid. + + >>> check_valid_ip("192.168.0.23") + True + + >>> check_valid_ip("192.255.15.8") + False + + >>> check_valid_ip("172.100.0.8") + True + + >>> check_valid_ip("254.255.0.255") + False + """ + ip1 = ip.replace(".", " ") + list1 = [int(i) for i in ip1.split() if i.isdigit()] + count = 0 + for i in list1: + if i > 254: + count += 1 + break + if count: + return False + return True + + +if __name__ == "__main__": + ip = input() + output = check_valid_ip(ip) + if output is True: + print(f"{ip} is a Valid IP address") + else: + print(f"{ip} is an Invalid IP address") From 6063957ace22ad4fd6f85509a2a1b446a4d42a5b Mon Sep 17 00:00:00 2001 From: Shubham Ganar Date: Sun, 8 Aug 2021 22:09:30 +0530 Subject: [PATCH 2/2] fixed typos error --- maths/check_valid_ip_address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/check_valid_ip_address.py b/maths/check_valid_ip_address.py index 320d3987c184..6e8d35ebc44c 100644 --- a/maths/check_valid_ip_address.py +++ b/maths/check_valid_ip_address.py @@ -9,7 +9,7 @@ def check_valid_ip(ip: str) -> bool: """ - print "Valid IP adddress" If IP is valid. + print "Valid IP address" If IP is valid. or print "Invalid IP address" If IP is Invalid.