String Manipulation (AQA GCSE Computer Science)

Exam Questions

17 mins6 questions
11 mark

The pseudocode in Figure 1 assigns two string values to two variables.

Figure 1

title ← 'computer science' 
level ← 'gcse'

Identify once choice that shows the result of concatenating the variable title with the variable level in Figure 1.

  • 'computer science gcse'

  • 'Computer Science GCSE'

  • 'computersciencegcse'

  • 'computer sciencegcse'

Did this page help you?

2a1 mark

Figure 1 shows an algorithm, represented using pseudocode, which assigns a different value to four variables.

Figure 1

country ← 'United States of America'
state ← 'California'
city ←'San Francisco'
landmark ← 'Alcatraz Island'

The variable x is assigned a value using the statement:

x ← LEN(state)

Using Figure 1, what is the value of x?

Identify one choice

  • 1

  • 5

  • 10

  • 12

2b1 mark

What is the result of concatenating the contents of the variables city and landmark in Figure 1?

Identify one choice

  • San Francisco Alcatraz Island

  • San Francisco,Alcatraz Island

  • San Francisco, Alcatraz Island

  • San FranciscoAlcatraz Island

2c1 mark

The subroutine SUBSTRING extracts characters from a given string.

For example, SUBSTRING(3, 5, 'Computing') would return put

The variable y is assigned a value using the statement:

y ← SUBSTRING(4, 7, landmark)

Using Figure 1, what is the value of y?

Identify one choice

  • Alca

  • Atra

  • land

  • traz

Did this page help you?

31 mark

Figure 4 shows a Python program that calculates car park charges.

The user inputs their car registration (eg MA19 GHJ) and the length of the stay.

The program then outputs the charge.

  • Line numbers are included but are not part of the program.

Figure 4

1 charge = 0
2 carReg = input("Enter your car registration: ")
3 while len(carReg) > 8:
4     displayMessage = " is not valid"
5     carReg = input(displayMessage)
6 hours = int(input("Enter your stay in hours: "))
7 if hours < 2:
8     charge = 0
9 else:
10    charge = hours * 2
11 print(charge)

Rewrite line 4 in Figure 4 to concatenate the car registration with the string " is not valid", and store the result in the variable displayMessage.

Your answer must be written in Python.

Did this page help you?

4a1 mark

Figure 8 box shows an algorithm represented using pseudocode.

  • Line numbers are included but are not part of the algorithm

Figure 8

1 names ← ['Lily', 'Thomas']
2 name1 ← 'Sarah'
3 name2 ← 'Freddie'
4 OUTPUT name1[0]
5 OUTPUT LEN(names)
6 var ← SUBSTRING(0, 3, name1)
7 OUTPUT var

SUBSTRING returns part of a string.

For example, SUBSTRING(3, 5, 'programming') will return the string 'gra'.

Identify one choice which shows the output of line 4 from the algorithm shown in Figure 8.

  • F

  • Freddie

  • Lily

  • S

  • Sarah

4b1 mark

Identify one choice which shows the output of line 5 from the algorithm shown in Figure 8.

  • 1

  • 2

  • 4

  • 5

  • 10

4c1 mark

State the output of line 7 from the algorithm shown in Figure 8.

Did this page help you?

12 marks

Figure 8 shows an algorithm represented using pseudocode.

  • Line numbers are included but are not part of the algorithm.

Figure 8

1 names ← ['Lily', 'Thomas']
2 name1 ← 'Sarah'
3 name2 ← 'Freddie'
4 OUTPUT name1[0]
5 OUTPUT LEN(names)
6 var ← SUBSTRING(0, 3, name1)
7 OUTPUT var

SUBSTRING returns part of a string.

For example, SUBSTRING(3, 5, 'programming') will return the string 'gra'

Two extra lines are being added to the end of the algorithm in Figure 8.

Fill in the gaps so the output from the new final line will be the string 'Thomasrah'.

var ← SUBSTRING( _____ , _____ , name1)
OUTPUT names[ _______ ] + var

Did this page help you?

17 marks

Write a Python program that inputs a character and checks to see if it is box lowercase or not.

Your program should work as follows:

  • gets the user to enter a character and store it in a suitable variable

  • determines if the entered character is a lowercase character

  • outputs LOWER if the user has entered a lowercase character

  • outputs NOT LOWER if the user has entered any other character

You should use meaningful variable name(s), correct syntax and indentation in your answer.

Did this page help you?