Note that your final mark will not be saved in the system.
Programming fundamentals (2.2) GapFill
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 inputStep 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 above that the algorithm will require some sort of selection. We can see from 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 =
("Enter a word or phrase")
The response of the user input is stored as 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 statement:
response:
case
:
substringStart = input("Enter the start position of your new substring")
substringLength = input("Enter the length of your new substring")
userString = userString.
We now need to make the program loop through the necessary steps:
continue = True
case "no":
continue = False
:
continue = True
Finally, we output the result: