Python Forum
Self Paced Web course - split ip and print each piece in binary and hex
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Self Paced Web course - split ip and print each piece in binary and hex
#3
Bad question. Would avoid boct and xoct completely.
ip = input("Enter an ip address : ")
octets = ip.split(".")
print("\n\n{:^15}{:^15}{:^15}{:^15}".format("Octet1","Octet2","Octet3","Octet4"))
print("-" * 80)
print("{:^15}{:^15}{:^15}{:^15}".format(*octets))
for x in range(4):
    print("{:^15}".format(bin(int(octets[x]))), end="")
print()
for x in range(4):
    print("{:^15}".format(hex(int(octets[x]))), end="")
print()
print("-" * 80)
You can get fancier with list comprehension
Reply


Messages In This Thread
RE: Self Paced Web course - split ip and print each piece in binary and hex - by jefsummers - Dec-04-2019, 06:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  name.split() + (And) + print question sklord 12 3,791 Mar-26-2022, 05:45 PM
Last Post: deanhystad
  Explain a piece of code SuuzyQ04 1 1,586 Nov-19-2020, 07:13 PM
Last Post: Gribouillis
  Binary to decimal, print the decimal rs74 3 2,098 Jul-12-2020, 05:25 PM
Last Post: DPaul
  Print Binary Tree - Python Daniel94 1 2,703 Jan-08-2020, 09:54 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020