GCSE Computer Science – String Manipulation: Strings and characters
MUST – Be able to access characters in a string
SHOULD – Be able to use slicing to access and edit specific characters within a string.
COULD – Be able to access and edit characters within a string to solve programming
problems.
Starter
Strings are very similar to lists. Answer the following questions relating to lists as a revision from the
previous topic.
Question Answer
1. Indexes in a list start at what value? 0
2. What will print? 30
3. What will print? 15
4. What will print? 10, 20, 30, 35
5. Re-write this using a range statement: For numbers
1. Write a program that defines a string and outputs each of the characters on individual lines.
You can either do this using several print statements or a FOR loop.
Screenshot your code
Screenshot a test
2. Write a program that asks the user to enter some text. Get the program to return a random
character from the string.
Screenshot your code
Screenshot a test
3. Write a program that stores a set word in a variable. Display the first half of the word to the
user using slicing.
Extension: You could get the user to enter the word, your program would need to calculate
which index was the half way point.
Screenshot your code
Screenshot a test
4. Extend the program in question 3 so that the user can guess the last half of the word. Tell
the user if they got the guess correct or not.
Screenshot your code
Screenshot a test
5. Try to fix the problem in the code on slide 12 of the PowerPoint. There is a missing space.
Screenshot your code
Screenshot a test
6. Write a program that will change a random character in a word, the new character does not
need to be random e.g. replace a random character with the letter ‘a’.
Display the new word and ask the user to guess the position of the changed character.
Screenshot your code
Screenshot a test
7. Develop a basic game of hangman. For an extra challenge you are not allowed to use FOR
loops in your answer!
You don’t need to display the hangman picture every time, just give the user 10 lives
.
Screenshot your code
Screenshot a test