This week is all about strings, in particular string methods. Of course, we also get more practice with loops and choices.
This week, you will submit your shell window at the end of the session. Try not to close it accidentally along the way.
You will also submit a responses.txt file this week. Download this template file and use it to record any answers or predictions asked for in the exercises.
Throughout the course, we have used built-in Python functions to compute values and to interact with users. Examples include, int(), float(), ord(), chr(), print() and input(). These are all names for operations that we want to execute.
As you read in Chapter 4, Python strings offer another kind of operation, methods. Recall that we invoke methods with a "dot" syntax, like this:
>>> name = 'eugene' >>> name.count('e') 3
Python provides a number of built-in methods for manipulating the case of strings, among them:
Let's figure out what they do by trying them out. Do not look them up in your textbook. Do not look them up with Google or any other search engine. Instead, try them out in the shell.
You may copy the expressions and paste them into your shell, one at a time.
Make up some test cases of your own.
Again, do not look them up in your textbook or on-line. Try them in the shell!
Suppose that every UNI email address was generated from the following formula:
The first 5 characters of your last name followed by the first initial of your first name followed by @uni.edu
For example:
Write a program called generateEmail.py This program should prompt the user for the first name and then prompt the user for their last name. It should then print that person's email address using the formula described above.
Look at splitCSV.html and study the Python code that prints out the items separated by commas in a string. This sort of processing for "comma-separated values" is useful for working with spreadsheets. It can be even more useful if we can do arithmetic with the items. For example:
Enter a student record: Mark Jacobson,20,17,20 Student Mark Jacobson has a grade of 19.0 points. Enter a student record: Mortimur Snurd,20,19,18,17,16,15,14,13 Student Mortimur Snurd has a grade of 16.5 points.
You must use a loop to process the string. You may not use Python lists or any other feature beyond what we have studied in class or Chapters 1-4.
You may use string methods such as find() if you like, or work through the string character by character. You may even use string_split.py as your starting point.
Make sure that your program files are complete and saved. Save your responses.txt file.
Submit your files for grading on the electronic submission system, at lab06 -- Strings and Their Methods.
As always, make sure you see the verification screen that says The files listed above were uploaded.
If you need any help, let me know.