Our site uses cookies. Some of the cookies we use are essential for parts of the site to operate and have already been set. You may delete and block all cookies from this site, but parts of the site will not work. To find out more about cookies on this website, see our Cookie Policy
Accept
© eRevision.uk and ZigZag Education 2025
This test is run by .
Note that your final mark will not be saved in the system.

Programming fundamentals (2.2) GapFill

Target Level
4-5
Running Total
0
0%
Attempt
1 of 3

You must fill all the gaps before clicking ‘Check Answers!’

Once you have decided on an algorithm to solve a problem, it is useful to think about the programming constructs that you will need to use.

For example, in this algorithm:

Step 1: Get user input
Step 2: Ask the user if they would like to make a substring from their input
Step 3: If they say yes, ask them for the start position and length of their desired substring
Step 4: Set the value of the input to be the substring specified by the user
Step 5: Repeat the previous three steps until the user says no
Step 6: Output the final value of the input

We can see from  Step 6Step 3Step 5Step 1 above that the algorithm will require some sort of selection. We can see from  Step 1Step 5Step 6Step 4 that it will also require iteration.

To start programming the algorithm, we should start from the first step and follow each step through in order.  First, we get input from the user:

userString =  intstrcharinput("Enter a word or phrase")

The response of the user input is stored as  a constanta filea constructa variable so that it can be used and edited later.

Step 5 tells us that steps 2-4 are in a loop:

do

We then move on to step 2, asking the user if they would like to make a substring from their input

response = input("Would you like to make a substring of " + userString + " (y/n)")

The next two steps depend on the result of the last string, so we need a  iterationbreakfunction callselection statement:

 untilcaseifswitch response:
case  response"response""yes"yes:
substringStart = input("Enter the start position of your new substring")
substringLength = input("Enter the length of your new substring")
userString = userString.  length(substringStart, substringLength)substring(substringStart, substringLength)substring(substringLength, substringStart)substring(substringStart)

We now need to make the program loop through the necessary steps:
continue = True
case "no":
continue = False
 case "else"defaultcase "default"elseif "n":
continue = True
 endifendswitchswitchcase "end"
 until continue == Trueuntil continue == Falsewhile continue != Truewhile continue == False

Finally, we output the result:

 userString("print")userString(print)print(userString)print("userString")

This is your 1st attempt! You get 3 marks for each one you get right. Good luck!

Pass Mark
72%