Exercise 10.1
Loop through the following string printing out each character.
Exercise 10.2
Loop through the following string in reverse printing out each character.
Hint: See Notebook 6 for how to reverse a string.
Exercise 10.3
In Notebook 5 we introduced the len()
function which returns the length of a string. Write your own code that counts the number characters in a string and then prints it out.
Hint: You will need a tally variable to keep a count of the number of characters.
Exercise 10.4
Many common tasks in Python usually have an inbuilt method. Counting the number of occurrences of a character in a string is a common thing to do.
Try googling "python count character in string" to see if you can discover a simpler method for counting "f"s in the following sentence. Then use that method to count "f"s.
Hint: Remember to count both lowercase and uppercase "f"s.