First python program

Introduction
The world of networking is abuzz with how software programming (aka python being the current flavour) has become an essential skill to learn if you wish to survive in your career.
I agree that going forward it is highly probable that you will come across opportunities to apply python knowledge to your job.

But it is hard to buy into the hype that (python) programming knowledge is the most critical skill for a network engineer.

If you search the Internet for current examples of python use cases in the network space the examples are largely confined to operations, such as:

– automating repetitive (CLI) tasks over a large nunber of devices
– logging into devices to collect output
– making simple configuration changes
– deploying base configuration templates enmass
– writing custom scripts to gather specific network status information

These examples are highly appropriate and useful for those dealing with scale and repetitive tasks. Automation saves time, money and removes human error.

However even with SDN and more orchestration tools deployed in future, the case for enough scripting or programming work to shift the balance of required skills in a network team to programming is still unproven.

Core engineering work will remain the focus for most of us in familiar areas of network design, project work, troubleshooting, change implementation work. Work that is largely outside the realm of writing, parsing or modifying python scripts.

But engineers never say ‘no’ to taking on more skills and having another useful tool. On that note, here’s me embracing the hype and my first foray into some basic syntax.

BMI program
This is a body-mass-index (bmi) calculation program.

The program asks for your weight and height and after computing the bmi will give you an indication if you are underweight, overweight or at the correct weight.
You can choose to enter your weight and height in metric or imperial measurements.

def CalculateBmi (weight,height):
bmi = round (weight / ((height/100) ** 2))
return bmi

def Result (bmi,name):
if bmi < 18:
print (f"{name} you are underweight")
elif bmi < 25:
print ("{} you are at the correct weight" .format (name))
else:
print ("{} you are overweight" .format (name))

def main():
your_firstname = input ("What is your firstname ?")
measure = input ("Do you prefer Metric, please answer (y/n) ?")
print()

if measure == "y" :
weight = input ("What is your weight in kgs ? ")
weight_in_kgs = int (weight)

height = input ("What is your height in centimetres ? ")
height_in_cm = int (height)
else:
weight = input ("What is your weight in lbs ? ")
weight_in_lbs = int (weight)
weight_in_kgs = weight_in_lbs * 0.45 # convert weight to kgs

&nbsp;

height_ft, height_inch = input ("What is your height in feet, inches. Please separate the values with a comma ? ").split(",")
height_in_inches = (int (height_ft) * 12) + int(height_inch)
height_in_cm = height_in_inches * 2.54 # convert height to cm

your_bmi = CalculateBmi (weight_in_kgs, height_in_cm)
print ("Your bmi is {} " .format (your_bmi))
print()
Result (your_bmi,your_firstname)


main()

 

Running the program

— metric measurment

What is your firstname ?John
Do you prefer Metric, please answer (y/n) ?y

What is your weight in kgs ? 70
What is your height in centimetres ? 168
Your bmi is 25

John you are overweight

— imperial measurment

What is your firstname ?Judy
Do you prefer Metric, please answer (y/n) ?n

What is your weight in lbs ? 120
What is your height in feet, inches. Please separate the values with a comma ? 5,3
Your bmi is 21

Judy you are at the correct weight