Wednesday, May 25, 2016

GIS5103 - Module 2 - Python Fundamentals Part 1

In this week's module I found the lecture assignments and exercises very valuable in assisting with the lab assignment.  We were tasked with creating a script that given a string full name would then split the full name and print only the last name.  The script then had to calculate the length of the last name assigned in the original string and then multiply that length by three and print the value.   Because variable names were provided in the assignment, I had a better understanding of the script code.  My first script contained seven lines and produced the desired results.

Results of Mod2_MThrush.py running script in PythonWin

After creating the script and running it successfully, I created a flow chart.  I know this process should be reversed; create the flowchart and then create the script.  This is a habit I will need to form as scripts will become more complex.

Flow Chart of Mod2_MThrush.py which prints the last name of an assigned full name string and the value of three times the length of the last name.
While I was completing the Process Summary, I realized there was a way to reduce at least one line of code in my script.  After successfully running my second script, I found an additional line that I could remove.  My final script contained 5 lines of code and produced the same results.  There is  always more than one way to solve a problem or "skin the cat", especially with scripting/programming.   Editing and modifying my original script enabled me to get some experience using Python Win and to better understand Python syntax.

No comments:

Post a Comment