ExercisesΒΆ

  1. What is the result of each of the following:

    1. ‘Python’[1]
    2. “Strings are sequences of characters.”[5]
    3. len(“wonderful”)
    4. ‘Mystery’[:4]
    5. ‘p’ in ‘Pineapple’
    6. ‘apple’ in ‘Pineapple’
    7. ‘pear’ not in ‘Pineapple’
    8. ‘apple’ > ‘pineapple’
    9. ‘pineapple’ < ‘Peach’
    1. ‘Python’[1] = ‘y’
    2. ‘Strings are sequences of characters.’[5] = ‘g’
    3. len(‘wonderful’) = 9
    4. ‘Mystery’[:4] = ‘Myst’
    5. ‘p’ in ‘Pineapple’ = True
    6. ‘apple’ in ‘Pineapple’ = True
    7. ‘pear’ not in ‘Pineapple’ = True
    8. ‘apple’ > ‘pineapple’ = False
    9. ‘pineapple’ < ‘Peach’ = False
  2. Assign to a variable in your program a triple-quoted string that contains your favorite paragraph of text - perhaps a poem, a speech, instructions to bake a cake, some inspirational verses, etc.

    Write a function that counts the number of alphabetic characters (a through z, or A through Z) in your text and then keeps track of how many are the letter ‘e’. Your function should print an analysis of the text like this:

    Your text contains 243 alphabetic characters, of which 109 (44.8%) are 'e'.
    

    
    
    

    (ex_8_3)


    
    
    

    (q3_answer)

  3. Write a function that will return the number of digits in an integer.


    
    
    

    (ex_7_10)


    
    
    

    (q5_answer)

  4. Write a function that reverses its string argument.


    
    
    

    (ex_8_5)

  5. Write a function that mirrors its argument.


    
    
    

    (ex_8_6)


    
    
    

    (q7_answer)

  6. Write a function that removes all occurrences of a given letter from a string.


    
    
    

    (ex_8_7)

  7. Write a function that recognizes palindromes. (Hint: use your reverse function to make this easy!).


    
    
    

    (ex_8_8)


    
    
    

    (q9_answer)

  8. Write a function that counts how many times a substring occurs in a string.


    
    
    

    (ex_8_9)

  9. Write a function that removes the first occurrence of a string from another string.


    
    
    

    (ex_8_10)


    
    
    

    (q11_answer)

  10. Write a function that removes all occurrences of a string from another string.


    
    
    

    (ex_8_11)

  11. Write a function called removeDups that takes a string and creates a new string by only adding those characters that are not already present. In other words, there will never be a duplicate letter added to the new string.


    
    
    

    (ex_8_19)

Next Section - Lists