In this week's GIS Programming lab, we learned more about how to write scripts, and the nature of some of the data types in Python, such as numeric values, strings and lists. We learned the definitions of expressions, statements, functions, methods and objects. We practiced using methods and wrote a small script in which the input is our full name, in the form of a list. Running the script causes the last name only to be output, as well as the number of letters in the last name times 3.
My output is shown above. It consists of my last name, and the number of letters in it (5) times 3 (15).
In order to write this code, I utilized the split method, to separate the whole name string into separate names/strings in a list, then indexing to select the last name from the list, and the length function combined with a simple multiplication operator, to find the number of letters in the last name times 3. Print statements were also included in the script to show the last name and for the number of letters times 3.
No comments:
Post a Comment