#C14188. Valid IPv4 Address Checker
Valid IPv4 Address Checker
Valid IPv4 Address Checker
In this problem, you are asked to determine whether a given string is a valid IPv4 address. An IPv4 address is valid if and only if it consists of exactly four decimal numbers separated by dots ('.'). Each number must be in the range \(0 \leq a_i \leq 255\) and must not have leading zeros (except for the number zero itself). Also, the address should not contain any extra spaces. For example, 192.168.0.1
is valid while 192.168.01.1
or 192.168.0.1
are invalid.
Your task is to implement the function with the following prototype:
def is_valid_ipv4_address(ip: str) -> bool:
The program should read the input IPv4 address from standard input and output either True
or False
on standard output depending on whether the address is valid.
inputFormat
The input consists of a single line containing the IPv4 address as a string. The string may contain spaces, which should be considered as part of the input.
outputFormat
Output a single line containing True
if the input string represents a valid IPv4 address, and False
otherwise.
192.168.0.1
True