Friday, June 6, 2014

Python Fundamentals Part I

This week we started compiling basic Python code. The key to understanding code is to understand the psuedocode.  For example, where do you start, what are the steps in the middle, and what should the end result be.  For our lab, the psuedocode would look like this:

  1. Create a string for your name
  2. Split that string into a list
  3. Print last name
  4. Find the length of the last name
  5. Multiple the length of the last name by 3
  6. Print length of last name times 3

This took some trial and error. As I was going along in my script, I would use the print command after each line of code to ensure that I was getting the correct response.  It took a while to wrap my head around the concept of creating the variable lastNameLen.  I had to realize that I had to tell the code what the variable lastNameLen would be equal to the last list item of my last name.  Once it clicked, the rest of the script seemed to fall into place.

The image below is the results of my script. You can see that my last name Williams is printed (step 3) and so is the number 24, which is the multiple of 8 (the number of letters in Williams) x 3.

Script Result

No comments:

Post a Comment