Difference between revisions of "Python String Exercises"

From WLCS
(Directions)
(Directions)
Line 4: Line 4:
  
 
== Directions ==
 
== Directions ==
Create a python file named ch7_YOURLASTNAME.py
+
Create a python file named "ch7_YOURLASTNAME.py".  In this file, complete the following exercises:
  
  

Revision as of 08:07, 13 May 2010

Objective

  • You will learn to create and access characters and slices of a string
  • You will learn to use a loop to traverse the characters of a string

Directions

Create a python file named "ch7_YOURLASTNAME.py". In this file, complete the following exercises:


  1. Create a string "The quick brown fox jumped over the lazy dog." in a variable s
    • Print out the first letter in s using the brackets (e.g. s[NUM])
    • Print out the letter "q" using s and the index 4
    • Print out the letter "x" using s and the corresponding index
    • Using string slicing, print out the word "brown"
    • Using string slicing, print out the word "lazy"
    • Using string slicing, print out starting at the word "jumped" through the end of the string
  2. Use the string variable s from Question 1. Create a loop that prints out every letter in the variable s
  3. Use the string variable s from Question 1. Create a loop that prints out every letter in s backwards starting from the end.
  4. Use the string variable s from Question 1. Create a loop that prints out every other letter in s starting from the beginning