ExercisesΒΆ
What is the result of each of the following:
- ‘Python’[1]
- “Strings are sequences of characters.”[5]
- len(“wonderful”)
- ‘Mystery’[:4]
- ‘p’ in ‘Pineapple’
- ‘apple’ in ‘Pineapple’
- ‘pear’ not in ‘Pineapple’
- ‘apple’ > ‘pineapple’
- ‘pineapple’ < ‘Peach’
- ‘Python’[1] = ‘y’
- ‘Strings are sequences of characters.’[5] = ‘g’
- len(‘wonderful’) = 9
- ‘Mystery’[:4] = ‘Myst’
- ‘p’ in ‘Pineapple’ = True
- ‘apple’ in ‘Pineapple’ = True
- ‘pear’ not in ‘Pineapple’ = True
- ‘apple’ > ‘pineapple’ = False
- ‘pineapple’ < ‘Peach’ = False
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'.
Write a function that will return the number of digits in an integer.
Write a function that reverses its string argument.
Write a function that mirrors its argument.
Write a function that removes all occurrences of a given letter from a string.
Write a function that recognizes palindromes. (Hint: use your
reverse
function to make this easy!).
Write a function that counts how many times a substring occurs in a string.
Write a function that removes the first occurrence of a string from another string.
Write a function that removes all occurrences of a string from another string.
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.