Comparison and Boolean Ops in Python

Python comparisons are unusual in that chaining comparisons is allowed, and works reasonably. Chained comparisons translate to a series of anded terms, repeating the middle. For instance, a < b == c <= d is interpreted as a < b and b == c and c <= d. The only other note is that the middle expression (4 in the below example) is evaluated only once. For a constant, this doesn’t matter, but it will make a difference for expressions which have a side-effect. Note that this does not always have the desired effect. For instance, 3 != 2 != 3 is true, which might not be what you wanted.

Continue reading

Hello World in Morse code on Raspberry Pi

Watch out! This tutorial is over 2 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

Somebody posted a tutorial on YouTube showing a LED blinking”hello world” in Morse code using a Raspberry Pi.  However, they only show the code executing, not how it was put together. They also don’t show the hardware setup 🙁

Continue reading

Port Scanner in Python

Watch out! This tutorial is over 2 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

This post will show how you can make a small and easy-to-use port scanner program written in Python. There are many ways of doing this with Python, but we’re going to do it using the built-in module Socket.

Do not run programs like this one against servers in the college. Behaviour like this could be seen as malicious and get you suspended!

Continue reading

Hello World in Python

Watch out! This tutorial is over 2 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

This is how you would display “Hello World” in Python.