This post will describe the exercises and solutions for week two of Kirk Byers Python for Network Engineers.

The second exercise of week two is the following:

We already have the knowledge to achieve this and the previous post went through all of the concepts needed to finish this task so I won’t bee too verbose with the code here.

The first part is to ask the user for an IP address using the “input()” function.

The next step is to split the IP address into octets using “split()”.

After that each octet is converted into binary with the following code:

Like in the previous post we have to convert the strings to integers before we can use “bin()” on them. We use list slicing to access the right string in the list.

Then all that is left is to print some pretty tables and reference our variables. We will use left aligned text and set the width to 20 characters.

We then test to run the code:

Mission accomplished! Code is available at Github.

Python – Kirk Byers Course Week 2 Part 2

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: