Functions in Python
Here I discuss functions in Python through code and problem statements as practiced in the Course 7: Automate Cybersecurity Tasks with Python. This lab is done in the Jupyter notebook.
1. Basic Alert Function:
Calling the alert() function that was defined earlier, that is how the statements inside the function are printed as an output.
2. Repeating Alerts with a Loop:
Using for loop inside the function and then calling it, as long as the iteration remains, the same line will get printed as an output.
3. Reading a List of Usernames:
Using a for loop inside a function to go through all the elements of the username_list and then print them.
4. Combining Names into One Line:
Displaying the same list using the string concatenation using the + sign.
5. Sorting Login Attempts:
Use of the built-in sorted() function to print the elements of the list in an ascending order.
Get Tehreem’s stories in your inbox
Join Medium for free to get updates from this writer.
6. Finding the Worst-Case Number:
Use of the built-in max() function to print the maximum number of failed login attempts in a month.
7. Passing Info into Functions:
Calling a function with parameters and arguments.
8. Adding Baseline Averages:
Calculating an average of a user’s daily logins into a system.
9. Doing Math with return:
Using the return statement instead can also be efficient.
10. Triggering Conditional Alerts:
Creating an alert if number of logins from the same user is more than or equal to 3 because this demands an investigation.
So, this was all about the functions in Python. I will see you in the next lab where I explore and learn more about the Python programming language and how to implement this logic into day-to-day SOC analyst tasks.








