I implemented a crude version of the game of Battleship in Python. This is all about x and y coordinates. How should one store such a pair of coordinates? I chose a tuple. A tuple in Python is a set of comma separated numbers. Normally they are programmed within parentheses. I just happened to represent the ship coordinates using tuples. Then I put those tuples in a list.
The good thing about tuples is that you access the elements of a tuple like you would a list, with brackets. A zero based index goes in the bracket. The values in the tuple are immutable. Once set, you cannot change them. This is fine as the ships in Battleship are not changing during the game.
Previously I had learned to use the int() function to convert a string to an integer. Well now I know there is also a str() function to convert an integer to a string. Useful information. Where to go next? I might implement a simple encryption method in Python. Or I might go full tilt and try to code the game of Othello. Still might also want to investigate a Python library. So much to learn. So little time.
Free Laundry
-
Apparently a lot of apartment buildings have coin operated laundry machines
in the basement. And guess what? You can order a key to unlock the payment
me...