CS 115 Pre-Lab 7 Instructions

Deadline: Tu 3/3/2015 at 7 AM

Refer to the Week 7 reading or other resources as necessary to complete this assignment.


Part 1: Strings

Answer Question 1 (the vocabulary question) in your pre-lab.

Then, go to the online Python 3 tutor to complete the remaining practice questions. You should try to predict the answers before putting them into the online tutor.

These questions cover string indexing, concatenation, repetition, slicing, and justification.

  1. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(x[2])
    
    Predict what this code will do and answer Question 2 in your pre-lab.
  2. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(x[2] + y[1])
    
    Predict what this code will do and answer Question 3 in your pre-lab.
  3. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(x + y)
    
    Predict what this code will do and answer Question 4 in your pre-lab.
  4. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(x + y)
    print(x)
    
    Predict what this code will do and answer Question 5 in your pre-lab.
  5. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(2 * y)
    
    Predict what this code will do and answer Question 6 in your pre-lab.
  6. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(y[1:5])
    
    Predict what this code will do and answer Question 7 in your pre-lab.
  7. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(y[:5])
    
    Predict what this code will do and answer Question 8 in your pre-lab.
  8. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(y[1:])
    
    Predict what this code will do and answer Question 9 in your pre-lab.
  9. For the following code...
    x = 'I am a string'
    y = 'me too'
    print(y[:])
    
    Predict what this code will do and answer Question 10 in your pre-lab.

Part 2: String methods; lists of strings

  1. For the following code...
    x = 'I am a string'
    print(x.upper())
    
    Predict what this code will do and answer Question 11 in your pre-lab.
  2. For the following code...
    x = 'I am a string'
    print(x.lower())
    print(x)
    
    Predict what this code will do and answer Questions 12 and 13 in your pre-lab.
  3. For the following code...
    x = 'I am a string'
    z = x.split()
    print(z[0])
    print(x)
    
    Predict what this code will do and answer Questions 14 and 15 in your pre-lab.
  4. For the following code...
    x = 'I am a string'
    for w in x.split():
        print(w, end="")
    print()
    
    Predict what this code will do and answer Question 16 in your pre-lab.
  5. For the following code...
    x = 'I am a string'
    y = x.split()
    print(len(y))
    
    Predict what this code will do and answer Question 17 in your pre-lab.

Part 3: Submit the pre-lab (due Tu at 7 AM)

Review your answers, and then click the Next button at the bottom of the Moodle quiz. Once you do that, you should see something similar to this:
Quiz attempt summary

Click the Submit all and finish button. You MUST do this so that your pre-lab can be graded! Once you have submitted your quiz, you should see something similar to this at the top of your Moodle window. The important part is that the State shows up as Finished.
Quiz confirmation