Learn Python With Me!
It’s time for another Medium article!
If you’ve taken a look at a few information security job postings, you’ll know that Python is a highly sought-after skill. I know C++ and C# yet those haven’t seemed to help me land an interview. But finally last week I decided to start learning Python. I’ve avoided it for the past 4 years because frankly, it seemed daunting. Do I really have the smarts to learn this new language? But you never know if you don’t try! (And spoiler alert: Anyone can learn a programming language with enough dedication!) I’m actively working on a few other projects (a home lab, Hackerone, and doing side work for a SecSaaS start-up company) outside of work hours, so I’m learning Python at work on lunch breaks and in between troubleshooting printers, Outlook, and hard drive failures for clients.
Resources: I asked my friend who took a Python course at George Fox for the textbook she used and found the PDF version. The book is Programming in Python 3 (Second Edition) by Mark Summerfield. I made it through the first chapter and then switched to watching this YouTube tutorial that’s about 4.5 hours long. I tried going back to the book but didn’t like the way it was written and started searching for another textbook. I remembered finding Getting Started with C++ by Tony Gaddis easier to understand. I had used it in my C++ class in college and even used it to prep for a Google interview about a year after not looking at C++ and easily being able to pick the language back up. So, I found Getting Started with Python by Tony Gaddis and have been using that. I highly recommend this book if you are looking for 1 resource that’s comprehensive and fairly easy to understand. I think textbooks are great for learning because they’re usually chock full of information- even if they’re dense and somewhat boring. If you can commit to focusing, a textbook is a great way to learn.
Learning method: I find it incredibly difficult to stick to one resource (or even subject) at a time. I’ve been trying my best to read through an entire chapter or get through a 4.5-hour video before moving onto something completely different (like the Hackerone CTF) but with Python it’s easiest for me to get the foundations down and then seeing how I can tweak the code to improve it.
Programs: I like going through the exercises that are given at the end of each chapter and completing each one. You can check out the Python programs I’ve finished and am going to be referencing in the rest of this article so far on my Github: here.
The first program’s purpose is to get familiar with the syntax of Python and using the print function. It’s called Personal Information and displays what’s within the print function. I wish that was my actual address…
The 2nd program’s purpose is to take user input, perform a calculation and display that calculation. If you read the prompt, it doesn’t say how to handle the input or to round the output to the nearest 100th decimal point. And in the real world it’s best practice to think ahead about the intended use of your program and also think about what the user could enter as input.
Testing out the program we can see that the output for the projectedProfit variable displays past the 100th decimal place. See the photo below. Sure, we can choose to ignore the numbers beyond the 100th decimal place but that’s annoying. As a user, using this program for monetary values, we would expect the output to display in currency format.
So I decided to optimize this code a bit by adding in (round(projectedProfit, 2)). The round function takes the variable projectedProfit and rounds it to the nearest 2nd decimal place. And below we see the optimized output:
Onto the 3rd program- Land Calculation. This is a simple program that takes the square footage of a plot of land from a user and calculates the acreage. Again, we’re not asked to optimize the output. But we should keep the end user in mind, so I’ve added the round function to the output as seen below:
And now the 4th program- the goal of this program is to take the prices of 5 items from the user and calculate the subtotal, sales tax, and the overall total. Now, right off the bat, I’m thinking this would be a great program for some recursion. But it’s sometimes it’s good to stick to basics at first and really understand how a program should work. See the finished program below:
Now that I know my program works, I’ll start incorporating recursion. I’m horrible at taking notes as I work so my thought process is missing here. But with a lot of googling, looking at example code, and testing, this is where I am at right now:
A recurring issue I ran into was formatting. Simply not indenting things properly can throw some errors. I also ran into issues calling the function. But I’ve managed to call the function as seen in the picture. However, I need to stop the program from iterating to get input and run through the calculations.
I’ll continue working on this code and reporting on my progress, but for today this is what I’ve accomplished and I’m happy with that.
If you’re learning something new and stumbling through it, keep going. It’s easy to forget that failure is a normal part of learning. But being persistent, consistent, and working through those failures to success is the rewarding part! Even if you spend just a few minutes a day learning a new skill, it all adds up. Trust the process!
And if you’d like to send me some tips for learning Python or getting my last program to work- connect with me on LinkedIn!