Year 10 Computing — Text inside a program
Work out how many characters a piece of text holds, which character sits at a given position, and what joining two pieces of text end to end gives.
Name: ________________________
1.The same short piece of text is joined to itself twice over. What does this program print?
tag = "ab" joined = tag + tag + tag print(len(joined))
2.Two pieces of text are joined and the length of the result is printed. What does this program print?
a = "web" b = "page" print(len(a + b))
- a) 2
- b) 4
- c) 8
- d) 7
3.The text is the same for all of these. Match each line to what it prints.
word = "network"
- print(word[0])
- print(word[3])
- print(word[6])
- print(len(word))
- print(word[len(word) - 2])
- k
- r
- n
- 7
- w
4.Two pieces of text are joined end to end here and the result is printed. What does the program print?
first = "sun" second = "rise" print(first + second)
5.Look carefully at what is between the quote marks in this one. What does it print?
words = "two words" print(len(words))
- a) 8
- b) 9
- c) 10
- d) 4
6.A character is read out of the joined text rather than out of either of the two pieces. What does this program print?
left = "top" right = "most" joined = left + right print(joined[3])
7.This program starts with a piece of text holding nothing at all and joins something on to it each time round. What does it print?
line = "" for n in range(0, 4): line = line + "ab" print(len(line))8.This one works out the last position for itself before reading a character from it. What does it print?
word = "screen" print(word[len(word) - 1])
Answer key — Year 10 Computing — Text inside a program
- 1. 6
- 2. d) 7
- 3. print(word[0]) → n; print(word[3]) → w; print(word[6]) → k; print(len(word)) → 7; print(word[len(word) - 2]) → r
- 4. sunrise
- 5. b) 9
- 6. m
- 7. 8
- 8. n