# Task

An IP address contains four numbers(0-255) and separated by dots. It can be converted to a number by this way:


Given a string `s` represents a number or an IP address. Your task is to convert it to another representation(`number to IP address` or `IP address to number`).

You can assume that all inputs are valid.

# Example

Example IP address: `10.0.3.193`

Convert each number to a 8-bit binary string
(may needs to pad leading zeros to the left side):
```
10  -->  00001010
0   -->  00000000
3   -->  00000011
193 -->  11000001
```
Combine these four strings: `00001010 00000000 00000011 11000001` and then convert them to a decimal number:
`167773121`


# Input/Output


`[input]` string `s`

A number or IP address in string format.

`[output]` a string

A converted number or IP address in string format.

# Example

For `s = "10.0.3.193"`, the output should be `"167773121"`.

For `s = "167969729"`, the output should be `"10.3.3.193"`.

Difficulty: introductory

Starter code:

def numberAndIPaddress(s):
	

Solutions:
from ipaddress import IPv4Address

def numberAndIPaddress(s):
    return str(int(IPv4Address(s))) if '.' in s else str(IPv4Address(int(s)))

from ipaddress import IPv4Address

def numberAndIPaddress(string):
    if '.' in string:
        return str(int(IPv4Address(string)))
    return str(IPv4Address(int(string)))

def numberAndIPaddress(s):
    if '.' in s:
        ans = str(int(''.join("{:0>8b}".format(int(n)) for n in s.split('.')), 2))
    else:
        s32 = "{:0>32b}".format(int(s))
        ans = '.'.join(str(int(s32[8*i:8*(i+1)], 2)) for i in range(4))
    return ans

def numberAndIPaddress(s):
    if "." in s:
        binary="".join("{:08b}".format(int(i)) for i in s.split("."))
        return str(int(binary, 2))
    else:
        binary="{:032b}".format(int(s))
        res=[str(int(binary[i:i+8], 2)) for i in range(0, len(binary), 8)]
        return ".".join(res)

def ipToNum(ip):
    return str(int(''.join(f'{n:08b}' for n in map(int, ip.split('.'))), 2))

def numToIp(nums):
    b = f'{int(nums):032b}'
    return '.'.join(map(str, [int(b[i:i+8], 2) for i in (0, 8, 16, 24)]))

def numberAndIPaddress(s):
    if '.' in s:
        return ipToNum(s)
    elif '.' not in s:
        return numToIp(s)

def numberAndIPaddress(s):
    ip2num = lambda ip: sum(el * (256 ** (4 - i)) for i, el in enumerate(map(int, ip.split('.')), 1))
    num2ip = lambda n: '.'.join(map(str, [n >> 24, n >> 16 & 255, n >> 8 & 255, n & 255]))
    return str(ip2num(s)) if s.find('.') > 0 else num2ip(int(s))

def ip_to_int(s):
    return str(int("".join(f"{int(n):08b}" for n in s.split(".")), 2))

def int_to_ip(s):
    return ".".join(str(int(b, 2)) for b in (f"{int(s):032b}"[i:i+8] for i in range(0, 32, 8)))

def numberAndIPaddress(s):
    return ip_to_int(s) if "." in s else int_to_ip(s)

from ipaddress import ip_address

def numberAndIPaddress(s):
     return str(int(ip_address(s)) if '.' in s else ip_address(int(s)))

import socket
import struct

def numberAndIPaddress(s):
    if '.' in s:
        return str(struct.unpack('>I', socket.inet_aton(s))[0])
    else:
        return socket.inet_ntoa(struct.pack('>I', int(s)))

from ipaddress import IPv4Address
def numberAndIPaddress(s):
    return str(int(IPv4Address(s)) if '.' in s else IPv4Address(int(s)))