Python Fundamentals - Learning a Programming Language


And here goes the Python fundamentals!
Module 2, Lab assignment 2 for GIS Programming at UWF:

We are off and running with some basic knowledge and practical practice with Python's fundamentals.
A series of exercises prepared us for using functions, methods, while and for loops. Using Spyder, we began with printing our name at the top of a dice game, and then debugging a couple errors in the dice game's block of script. One error was easy to find, the other was trickier. We needed to recognize that it was a string, and an argument was being written as an integer instead. Once fixed, we get a nice print out of a list of players rolling to win:


The last three lines were sections of script we had to create. At first, I tried to complicate it by adding too many lines of code doing different things. Learning a scripting language is very conceptual, it can be easy to find and memorize important functions, but the key is how they are written. Once I refined my code with simple lines, using what we learned in our exercises, it began to click.

First, we wrote an if-else statement for an integer "3", defined as unluckyNum. If the number "3" is present in the luckyList, it would be removed and reprinted. If the "3" was not present, the word "LUCKY!" would print instead. To count and remove the "3", two different while loops were used. It took a few tries to get this right, a lot like a puzzle. Luckily, for me, this was a fun puzzle.

This assignment was fantastic practice!
The possibilities of scripting with Python are overwhelming, endless, and exciting.
Next up: Debugging!

Comments