ลบ leading zeros จาก IP address โดย split ด้วย '.' แปลงเป็น int แล้ว join กลับ
ตัวอย่าง
Input: 200.040.009.400 Output: 200.40.9.400
อัลกอริทึม
- รับ IP address
- Split ด้วย '.' ได้ list ของ octets
- แปลงแต่ละ octet เป็น int (ลบ leading zeros อัตโนมัติ)
- แปลงกลับเป็น str และ join ด้วย '.'
โค้ดตัวอย่าง
def IP(ip):
zeroip = ".".join([str(int(i)) for i in ip.split(".")])
return zeroip
ip = input("Enter the IP address: ")
print("New Ip Address:", IP(ip))
ผลลัพธ์
Enter the IP address: 200.006.020.900 New Ip Address: 200.6.20.900