Difference between revisions of "Python String Exercises"

From WLCS
(New page: Directions: Create a python file named ch7_YOURLASTNAME.py # 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 b...)
 
Line 8: Line 8:
 
#* Using string slicing, print out the word "lazy"
 
#* Using string slicing, print out the word "lazy"
 
#* Using string slicing, print out starting at the word "jumped" through the end of the string
 
#* Using string slicing, print out starting at the word "jumped" through the end of the string
 
 
# Use the string variable s from Question 1.  Create a loop that prints out every letter in the variable s
 
# Use the string variable s from Question 1.  Create a loop that prints out every letter in the variable s
 
 
# Use the string variable s from Question 1.  Create a loop that prints out every letter in s backwards starting from the end.
 
# Use the string variable s from Question 1.  Create a loop that prints out every letter in s backwards starting from the end.
 
 
# Use the string variable s from Question 1. Create a loop that prints out every other letter in s starting from the beginning
 
# Use the string variable s from Question 1. Create a loop that prints out every other letter in s starting from the beginning

Revision as of 09:19, 7 April 2010

Directions: Create a python file named ch7_YOURLASTNAME.py

  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