A Level Computer Science
A Level Computer Science
On the following pages you’ll find programming theory and several challenges. You’ll need
to read through the theory, try out the sample code provided, and then have a go at the
challenges. Do feel free to do extra research when working through the challenges, such as
through Google and Stack Overflow. The primary language for A level is Visual Basic and I
would recommend you use this. If you are very confident with programming and would
prefer to use C#, then you could use this instead.
Before you get started you will need to install "Visual Studio Community Edition" which you
can download for free here: https://visualstudio.microsoft.com/downloads/
1. Open Visual Basic Express or Visual Studio Express. This guide is written for versions 2008-
2015.
2. Choose File… New Project…
3. Choose Visual Basic… Console Application…
4. Make sure you name your program appropriately, e.g. “Objective 1 Task 1” and choose an
appropriate place to save the project. Note, Visual Basic programs consist of many
individual files grouped into a solution and therefore you should enable ‘Create directory for
6. When you save your work, make sure you choose Save All
7. When you want to open your work again, choose Open Project…, not Open File. Find
the .sln file.
8. When working on challenges, remember to put Console.Readline() at the end of your
program, otherwise the code will run, and end before you can see the output!
Objective 1:
Understand how to output text strings
In this objective you learn how to output text to the screen.
Tasks
1. Try entering the following commands and see what happens:
Console.WriteLine("Hello World")
Console.ReadLine()
2. Try entering the text without the speech marks and see what happens:
Console.WriteLine(Hello World)
Console.ReadLine()
Note the difference. One works and one doesn’t! If you want to output text to the screen it must be
included in speech marks. Text is called a string in programming and must be enclosed in double
quotes.
3. Try entering the following commands and see what happens:
Note how an ampersand symbol (&) joins strings together. This is called concatenation.
4. Try this sequence of instructions:
'Start of message
Console.WriteLine("Hello World" & " this is my first program.")
'Blank line
Console.WriteLine()
'End of message
Console.WriteLine("I am learning to code...")
Console.WriteLine("...and it is fun")
'Wait for user to exit
Console.ReadLine()
Note the apostrophe symbol enables you to insert a comment in the code. The computer ignores
the comments, but they help to introduce the program and allow you to leave notes in the code to
make it easier to understand later.
Objective 2:
Understand how to input strings and numbers into variables
In this objective you learn how to get input from the keyboard to use in your program.
Tasks
1. Try entering the following commands and see what happens:
'Declare variables
Dim name_entered As String
'Inputting strings
Console.WriteLine("Hello")
Console.WriteLine("What is your name?")
name_entered = Console.ReadLine
Console.WriteLine("Thank you " & name_entered)
'Wait to close the program
Console.ReadLine()
Objective 3:
Understand string manipulation functions
In this objective you learn how to extract and change data that has been input.
Tasks
1. Try entering the following commands and see what happens:
2. Change the program to ask for an email address, outputting the string in lowercase using
LCase() instead of UCase.
5. Change the program to output the last 12 characters in the sentence using Right() instead
of Left().
Objective 4:
Understand how to use selection statements
In this objective you learn how to make different parts of your program run depending on the value
of variables.
Tasks
1. Try entering the following commands and see what happens:
2. Try entering the following commands and run the program three times with the test data:
6, 51 and 70.
Note how the program only executes instructions if the condition is true i.e. the score is
more than 40, and how it is possible to use an else statement to run an alternative set of
commands if the condition is false.
5. Try entering the following commands and run the program three times with the test data:
1, 3, 5.
Note how ‘And’ can be used to check if both conditions are true. You can also use ‘Or’ if only
one condition needs to be true and ‘Not’ as an alternative to does not equal.
Note how the number was input as a string, not an integer, yet greater than and less than
operators still work to check if the input was between 1 and 2. That’s because the ASCII value of
the character is being checked, not the actual number. This approach is helpful as it prevents
the program crashing if a character is input instead of a number.
6. Try entering the following commands and see what happens:
Note how it is possible to use a Select Case… End Select structure to have multiple branches
rather than just true or false.
Objective 4: Key learning points
How to use selection statements
Checking the value of a variable and executing instructions depending on the outcome of the
check is known as a selection.
The instructions that are executed as a result of a selection is known as a program branch.
The logical checking of a variable against another value is known as a condition.
Select/Case commands can be used instead of multiple if statements.
Code for each program branch should be indented.
It is good practice to comment a selection to explain its purpose.
One ‘If’ can be placed inside another ‘If’, this is known as nesting.
'Declare variables
Dim power_of_result As Integer
Dim number1, number2 As Integer
Dim division_result As Decimal
Dim integer_division_result As Integer
Dim modulus_result As Integer
'Make calculations
power_of_result = number1 ^ number2
division_result = number1 / number2
integer_division_result = number1 \ number2
modulus_result = number1 Mod number2
'Output results
Console.WriteLine()
Console.WriteLine(number1 & " to the power of " & number2 &
" is " & power_of_result)
Console.WriteLine(number1 & " divided by " & number2 &
" is " & division_result)
Console.WriteLine(number1 & " divided by " & number2 &
" is " & integer_division_result)
Console.WriteLine(number1 & " divided by " & number2 &
" has a remainder of " & modulus_result)
Console.ReadLine()
End Sub
'Declare variables
Dim random_number As Integer
'Generate a new random number seed
Randomize()
'Roll the dice
random_number = CInt(Rnd() * 5) + 1
Console.WriteLine("You rolled a " & random_number)
Console.ReadLine()
3. Change the program so that it outputs a 10 sided dice.
4. Change the program so the user can choose to roll a 4, 6 or 12 sided dice.
Rnd()
Example code: x = CInt(y * rnd()) +1
x becomes a random number between 0 and y. Rnd returns a decimal number between 0 and 1.
We multiply this by the range of numbers and convert it to an integer in order to get a single round
number. +1 is optional. By adding 1 the code will not return 0 as a random number. If that is
desired, do not include the +1, but remember y is the range of numbers, so if y is 5 then the
returned number will be between 0 and 4.
Randomize()
Example code: Randomize()
Computers are not able to generate truly random numbers. Instead they make a calculation using
“seed” numbers, and return numbers from a sequence. Without the keyword Randomize you would
get the same set of random numbers each time the program is run! Randomize creates a new seed
and therefore a new set of random numbers each time the program is run.
CInt()
Example code: x = CInt(y)
x becomes the integer of y, or y rounded down to the nearest whole number.
CDec()
Example code: x = CDec(y)
x becomes the decimal value of y
CStr()
Example code: x = CStr(y)
x becomes a string of y
Objective 6:
Understand counter controlled iterations
In this objective you learn how to get code to repeat itself a given number of times without having to
enter lots of repeating statements.
Tasks
1. Try entering the following commands and see what happens:
For counter = 1 To 5
Console.WriteLine("This is how you get code to repeat")
Next
Console.ReadLine()
2. Try changing the number 5 and see what happens. Also try changing the number 1 and see
what happens.
3. Modify the code as shown below. Run the program and see what happens. Note how the
value of the counter variable changes.
For counter = 7 To 12
Console.WriteLine("The counter is " & counter)
Next
Console.ReadLine()
Next
Console.ReadLine()
Note how we can now loop through all the letters in a word by combining an iteration with
string manipulation commands. Also note how commands inside an iteration are indented to
make the block of code easier to read.
Objective 6: Key learning points
Counter controlled iterations
An iteration is a section of code that is repeated.
Iterations are also known as loops.
Counter controlled iterations are used when you want to iterate a known number of times.
Counter controlled iterations use a variable which can be used within the code to know how
many times the code has been run.
Code is indented within an iteration to make it easier to read.
It would be good practice to comment code before an iteration to explain what is
happening.
Incrementing a variable increases its value by one.
Decrementing a variable decreases its value by one.
One ‘For’ loop can be put inside another ‘For’ loop. This is known as nesting.
Step determines by how much the counter increments. By default this is 1 and therefore step 1 is
not necessary. To count backwards, a negative value can be used for step. E.g.
For counter = 5 to 1 step -1
Console.WriteLine(counter)
Next
Objective 7:
Understand condition controlled iterations
In this objective you learn how to get code to repeat continually until a condition is met.
Tasks
1. Try entering the following program and see what happens by entering a few numbers and
ending by entering zero:
Note that the While statement can be placed either at the beginning of the iteration (as in program
1) or at the end of the program (as in program 2). Although these iterations both use the same
commands, they are not the same.
When the While number_entered > 0 condition is placed with the Do statement, the code
inside the iteration may not execute at all because the value of number_entered is checked first.
When the While number_entered > 0 condition is placed with the Loop statement, the code
inside the iteration must executae at least once because the value of number_entered is not
checked until the end.
Objective 8:
Understand subroutines, procedures and functions
In this objective you learn how to divide your program into more manageable sections to make it
easier to read and reduce the need for entering repeating code.
Tasks
1. Try entering the following program and see what happens:
'Outputs stars
Sub OutputLineOfStars()
Dim count As Integer
For count = 1 To NoOfStars
Console.Write("*")
Next
'Move to next line
Console.WriteLine()
End Sub
There are two ways to share data between subroutines. In the first program, the variables were
declared outside of any subroutine. That means they are global variables to the program, and their
values can be accessed, shared and changed by any subroutine in the program.
In the second program the variables ‘number’ and ‘max’ are declared in subroutine main(). Their
values are then passed into the subroutine outputrandoms. The values of the variables become n
and m in the subroutine outputrandoms. The variables n and m are different variables to number
and max, but the value stored in number and max was passed into n and m. This is also known as
passing by value, hence the command ByVal. In this example, the variables n and m are lost at the
end of the outputrandoms subroutine. That means they are local variables to the subroutine.
3. Try entering this program and see what happens:
'How functions can be used
Sub main()
Dim num1, num2 As Integer
Console.WriteLine("Enter the first number: ")
num1 = Console.ReadLine
Console.WriteLine("Enter the second number: ")
num2 = Console.ReadLine
Console.WriteLine("The floor number is: " & floor(num1, num2))
Console.ReadLine()
End Sub
4. Change the function so it receives the length of two sides of a right angled triangle, and
returns the length of the hypotenuse (h2 = o2+a2)
End Sub
Creates a subroutine called max. Two parameters are passed into max, with local variables x and y
holding their values.
max would be called with: x=max(6,9)
6 would be passed as a parameter to variable x. 9 would be passed as a parameter to variable y.
Function… Return… End Function
Example code: Function max (ByVal x as integer, ByVal y as integer) As
Decimal
Return z
End Sub
Creates a function called max. Two parameters are passed into max, with local variables x and y
holding their values.
max would be called with: n = max(6,9)
6 would be passed as a parameter to variable x. 9 would be passed as a parameter to variable y.
The value returned to n would be z, which in this case is a decimal because the function was
declared with As Decimal to indicate the data type of the return value.
Objective 9:
Understand arrays and lists
In this objective you learn how to store multiple items without having lots of different variables.
Tasks
1. Try entering the following program and see what happens:
Sentence is an example of an array: a group of elements with the same name and data type.
Think of an array as a table:
Identifier: sentence
Index: 0 1 2 3 4
Data: The quick grey fox jumps
2. Try this modification to the program to allow the user to change the colour of the fox:
You can then put data into the array using the syntax:
item(0) = "Alpha"
item(99) = "Omega"
Note that indexes always start at zero. So, one hundred elements is 0-99.
4. The power of arrays often comes by combining them with iterations.
Enter this code as an alternative to the first program and notice how the amount of code is
much reduced when you use a for loop to output each of the elements in the array.
5. Try entering this program and test by entering 8743 when prompted for a product code:
Note how an iteration and Boolean variable can be used to go through all the indexes of an
array to find an item.
This is not the best way to write this program, but does illustrate how a number of
programming concepts can be combined.
An alternative to an array is a list. An array is thought of as a static data structure because it has a
fixed size at run time. A list is a dynamic data structure that grows and shrinks to accommodate the
data stored in it. Lists also contain additional methods and properties that allow you to interrogate
or manipulate the list more easily than an array.
8. Change the program so the inventory is output and the user can choose which item to drop.
Objective 9: Key learning points
Understand arrays and lists
Arrays are variables that have multiple elements, all of the same data type.
Arrays are a static data structure because the size of the array does not change when the
program is running.
Lists are dynamic data structures because the size of the list changes when the program is
running.
An array or list has an identifier: the name of the array.
An array or list has an index which points to one element of the array/list.
Indexes start at 0.
An array has multiple elements: the data stored in it.
Arrays can be single dimension (one set of data) or be multi-dimension (having more than
one set of data)
Lists have methods that are operations that can be performed on the list with no additional
code written by the programmer.
Objective 10:
Understand serial files
In this objective you learn how to read and write data to files so it can be saved and loaded again
later.
Tasks
1. Try entering the following program and see what happens:
3. Change the program so that 3 lines of text are written to a file and read back in again.
It is often useful to read in all the data from a file line by line until you reach the end of the file. To
do this we would want to combine an iteration with a file read.
4. Try entering the following program and see what happens:
Objective 11:
How to handle exceptions for validation
In this objective you learn how to prevent your program crashing if it receives invalid data.
Tasks
1. Try entering the following program and use the test table of data to see what happens:
A program should not crash because it has bad data input. The potential for errors should be
considered by the programmer.
2. Try entering the following program and use the test table of data to see what happens:
'Get numbers
Try
Console.WriteLine("Enter a number:")
num1 = Console.ReadLine
Console.WriteLine("Enter a number:")
num2 = Console.ReadLine
Catch
Console.WriteLine("Invalid entry.")
End Try
'Output
Try
answer = num1 / num2
Console.WriteLine(num1 & " divided by " & num2 & " is " &
answer)
Catch
Console.WriteLine("Unable to divide.")
End Try
Console.ReadLine()
Catch
Console.WriteLine("Division by zero")
End Try
‘Try’ is the keyword to put before a run time error is likely to occur. The code following ‘Catch is the
code to execute if an error occurs.
Now for the challenges….
Objective 1: Challenges
You should attempt both challenges.
Visual dice challenge
Difficulty:
Write a program that will output the number 5 on a dice like this:
oooooooooooo
o o
o # # o
o # o
o # # o
o o
oooooooooooo
To calculate volume in litres, multiply length by depth by height and divide by 1000.
radius
Objective 3: Challenges
You should attempt one difficulty challenge, one difficulty challenge, and one difficulty
challenge.
Initials & surname challenge
Difficulty:
Write the program from the flowchart below to ask for a person’s forename and surname,
outputting their first initial and the rest of their name in capitals. E.g. ben white = B WHITE
Start
Input forename
Input surname
Forename: Simon
Surname: Hall
The program needs to find the space and then extract the characters to the left and right of the
space into two different variables.
Objective 4: Challenges
You should attempt one difficulty challenge, one difficulty challenge, and one difficulty
challenge.
Under age challenge
Difficulty:
Write a program that asks for your age. If you are over 18 it outputs the message, “Over 18”,
otherwise it outputs, “Under age”.
Water temperature challenge
Difficulty:
Write a program that reads in the temperature of water in a container in Centigrade and displays a
message stating whether the water is frozen (zero or below), boiling (100 or greater) or neither.
Vocational grade challenge
Difficulty:
Write a program that allows you to enter a test mark out of 100.
The program outputs “FAIL” for a score less than 40, “PASS” for a score of 40 or more, “MERIT” for a
score of 60 or more and “DISTINCTION” for a score of 80 or more.
Extended visual dice challenge
Difficulty:
For a six sided dice, write a program that asks for a number and outputs that number as a graphical
dice. E.g.
oooooooooooo
o o
o # o
o # o
o # o
o o
oooooooooooo
Start
Input number1
from keyboard
Input number2
from keyboard
Nitrate challenge
Difficulty:
When keeping fish, one of the goals to reduce algae is to keep nitrates to a minimum. One way of
doing this is to dose a carbon source which nitrifying bacteria within an aquarium consume together
with nitrates. The carbon source has to be dosed very precisely. Write this program to determine
the dose:
Start
Yes Is nitrate No
above 10?
Output
“Dose 3ml” Yes Is nitrate
above 2.5?
No
No
Stop
Portfolio grade challenge
Difficulty:
Write a program that inputs a mark from the keyboard for sections of a project: ‘analysis’, ‘design’,
‘implementation’ and ‘evaluation’. The program should output the total mark, the grade, and how
many more marks were needed to get into the next mark band.
Grades are:
<2 U
2 1
4 2
13 3
22 4
31 5
41 6
54 7
67 8
80 9
If the user enters Alkali metals, the program outputs the data for all the elements in the alkali metals
group.
You only need to get this working for 6 elements from two different groups.
Objective 5: Challenges
You should attempt one difficulty challenge, one difficulty challenge, and one difficulty
challenge.
RPG dice challenge
Difficulty:
In many RPG games, a number of different sided dice are used, not just the standard 6 sided dice.
Write a program that asks the user how many sides a dice has and outputs a random number for
that dice.
Divisible challenge
Difficulty:
Write a program that asks the user for two numbers. The program should output whether the two
numbers are exactly divisible by each other. If not, it should return the remainder. If the user enters
a 0 the program should give an error message. Use the test table below to understand the correct
outputs for this program:
Input 1 Input 2 Expected output
3 9 9 is exactly divisible by 3
5 15 15 is exactly divisible by 5
8 23 23 is not exactly divisible by 8, there is a remainder of 7
10 12 12 is not exactly divisible by 10, there is a remainder of 2
0 7 Error: you cannot divide by 0
Start
Roll 3 dice
Score =
total on the 3 dice
Yes Are two of the
dice equal?
Score = No
sum on the 2 equal dice
Score = 0
Output score
Stop
Month challenge
Difficulty:
Write a program that lets the user enter a year, and a month number between 1 and 12. The
program outputs the month name for that month number and the number of days in the month.
The input 3 would therefore display March has 31 days.
Remember February has 28 or 29 days depending on whether it is a leap year. It is a leap year if the
year is exactly divisible by 4.
Objective 6: Challenges
You should attempt one difficulty challenge, one difficulty challenge, and one difficulty
challenge.
Square numbers challenge
Difficulty:
Write the program to output all the squares of a number between 1 and 20 as described in the
flowchart below.
BEGIN
Counter
Yes
END start 1
Is = 20?
No
Squared =
counter * counter
Output a string
using counter and
squared variables
as shown below
The output should be:
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16
FizzBuzz challenge
Difficulty:
Write a program that outputs the numbers from 1 to 100. But for multiples of three output “Fizz”
instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples
of both three and five output “FizzBuzz”
Maths test challenge
Difficulty:
Write a program that could be used in an infant school to prompt a child with ten simple random 1
digit maths additions, e.g. 4+7= The user enters their answer and the computer tells them if they are
correct. At the end of the test the program outputs how many problems the child got right.
Objective 7: Challenges
You should attempt one difficulty challenge, one difficulty challenge, and one difficulty
challenge.
Menu selection challenge
Difficulty:
Write a program that presents a simple menu to the user: 1. Play Game 2. Instructions 3. Quit
The program should ask the user for a number between 1 and 3 and will output “Let’s go” only when
a valid entry is made, repeating the menu selection until a valid entry is made.
Compound interest challenge
Difficulty:
Write a program that shows how compound interest grows in a bank savings account. The program
should ask the user to input their current balance, the interest rate (0.04 would be 4%) and the
desired balance to reach. The program should output the new balance each year until the desired
balance is reached. Interest is added to the balance each year.
e.g.
£100 starting balance – 4% interest rate (0.04)
Year 1: New balance = 100 + ( 100*0.04) = £104
Year 2: New balance = 104 + (104*0.04) = £108.16
Year 3: New balance = 108.16 + (108.16*0.04) = £112.49
Gamertag challenge
Difficulty:
A gamertag is a username on a typical games console that other players can identify the player with.
There are some limitations to them, such as, it cannot be longer than 15 characters.
Write a program to input a valid gamertag and keep asking for a new gamertag until a valid entry is
made.
Pseudocode
1.0 Write a comment to explain the program checks the length of gamerTags entered.
2.0 Set a variable called valid_gamertag = true
3.0 Start a condition controlled iteration to check valid_gamertag
4.0 Output a message on the screen to say gamertags must be less than 15 characters.
5.0 Get a gamertag from the keyboard and put it into a variable called gamertag.
6.0 Using the function len() put the number of characters in gamertag in a variable called
gamertag_length.
7.0 Check if the length of gamertag is more than 15 characters by comparing gamertag_length to the
number 15.
7.1 Output a message to say ‘your gamertag is too long’ if it is of an invalid length.
7.2 Output a message to say ‘gamertag accepted’ if it is of a valid length.
8.0 End iteration
XP Challenge
Difficulty:
In many online multiplayer games, players are awarded experience points (known as XP) for
completing a variety of objectives in the game. When the player has accumulated enough XP, their
rank increases (they rank up) and their XP resets to zero (although extra XP is carried over). Each
rank requires more XP than the one before.
Write a program that:
Allows the user to keep entering XP for a game until it is 2000 or more.
When the XP reaches 100, ‘Promoted to Corporal’ is output.
Pseudocode
1.0 Set the player’s total XP to be 0
2.0 Set the player’s rank to be 1
3.0 Loop while the player’s XP is less than 2000
3.1 Ask the user to enter the XP earned in the last game
3.2 Add the XP earned from the last game to the total XP
3.3 Check if the XP earned is more than that required to be a Corporal and that their rank is 1
3.3.1 Tell the player they have been promoted
3.3.2 Set XP back to zero but carry over any XP left
3.3.3 Set player’s rank to be 2
3.4 Display the total XP
Extend the program so that the player ranks up according to the table below:
Objective 8: Challenges
You should attempt one difficulty challenge, one difficulty challenge, and one difficulty
challenge.
VAT challenge
Difficulty:
Write a program that asks the user for a price of an item. Include a function that returns the VAT for
the item. This should be output in the main program.
Conversion challenge
Difficulty:
Write a program that provides a conversion utility, converting from metric to imperial
measurements. The list of possible conversions can be presented to the user in a menu.
Each conversion should be a separate subroutine or function to allow the program to be modular
and added to later.
Darts challenge
Difficulty:
Darts is a game where the objective is to reach a score of zero starting from 501. A player throws 3
darts and their total from the throw is subtracted from their score. A player has to achieve a score
of exactly zero to win the game. A throw that would result in a score below two does not count.
Create a program to allow the user to enter a total from their darts. The program should then
subtract this from their current score if the remaining score would be greater than one.
The player should win the game when their score becomes exactly zero.
Pseudocode
1.0 Set the player’s score to be 501
2.0 Display the message: New game. Player starts at 501 points.
3.0 Loop while the player’s score does not equal zero
3.1 Ask the user to enter the total from 3 darts
3.2 Check if the player’s score minus the total is greater than 1
3.2.1 Subtract the total from the player’s score
3.2.2 Display the player’s new score
3.3 Else check if the player’s score minus the total equals 0
3.3.1 Subtract the total from the player’s score
3.3.2 Display the message: Player 1 wins the game
Objective 9: Challenges
You should attempt one difficulty challenge, one difficulty challenge, and one difficulty
challenge.
Text dice challenge
Difficulty:
Write a program that generates a random number and outputs the word, “one”, “two”, “three”,
“four”, “five” or “six” without using a condition statement like ‘if’.
Notebook challenge
Difficulty:
Write a program that allows the user to store up to 10 notes. The program should have this
functionality on a continual loop:
1. Output all the notes stored, numbered 0-9.
2. Ask the user to enter a number for a note to change.
3. Ask the user to enter the new note.
4. Over-write any existing note stored at that position.
Tanks challenge
Difficulty:
Tanks is a game for two players. At the start of the game, each player places 10 tanks on a board but
does not reveal their location to their opponent. Each tank occupies one square on the board. Each
player takes it in turn to enter a grid reference, e.g. 1,5. The player destroys the tank if the square is
occupied by a tank. The player to destroy all their opponent’s tanks first wins.
Example tanks board:
More Challenges
These challenges should only be attempted after difficulty challenges have been successfully
completed in all the required objectives.
Word extractor challenge
Difficulty:
Requires knowledge of objectives 1-3
Write a program that outputs the sentence: Quick brown fox jumps over the lazy dog. The user can
then enter the word to be cut from the sentence. The sentence is then output with the word
removed.
Hours worked challenge
Difficulty:
Requires knowledge of objectives 1-4
Write a program that asks the user for the number of hours worked this week and their hourly rate
of pay. The program should calculate the gross pay. If the number of hours worked is greater than
40, the extra hours are paid at 1.5 times the rate. The program should display an error message if
the number of hours worked is not in the range 0 to 60.
ROT13 challenge
Difficulty:
Requires knowledge of objectives 1-6
ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in
the alphabet. ROT13 is a special case of the Caesar cipher, developed in ancient Rome. ROT13 is
used in online forums as a means of hiding spoilers, punchlines and puzzle solutions from the casual
glance. Create a program that allows the user to enter plain text, and the ROT13 cipher is output.
Extend the program to allow cipher text to be input, with the plain text output.
Change calculator
Difficulty:
Requires knowledge of objectives 1-7
Write a program that outputs the change to be given by a vending machine using the lowest number
of coins. E.g. £3.67 can be dispensed as 1x£2 + 1x£1 + 1x50p + 1x10p + 1x5p + 1x2p.
Parser challenge
Difficulty:
Requires knowledge of objectives 1-8
Write a program that allows the user to enter an addition in the format: 16+8. There may be any
number of digits and additions in the input string. E.g. 16.4+108+9 is also a valid input. The parser
should be a function that returns the answer.
Blackjack challenge
Difficulty:
Requires knowledge of objectives 1-8
Create a program that plays a game of Blackjack between the player and computer. The program
should:
Deal two cards to the player and computer. One of the dealers cards is shown face up. All
other cards are dealt face down.
Cards 2-10 are face value. All picture cards are 10. Ace is 1 or 11, player may choose.
Once the card have been dealt ask the user if they want to twist or stick.
If the user twists then a new card is dealt and that is added to their total.
If the player busts (goes over 21) the dealer wins.
Once the player sticks, the dealer turns over his card and may twist or stick.
The player or dealer cannot stick below 16.
If the dealer busts then the player wins.
If both players stick, the player closest to 21 wins.
Lottery challenge
Difficulty:
Requires knowledge of objectives 1-8
In a lottery, players pick 6 numbers between 1 and 59. Six unique random balls are then output,
together with a “bonus ball”. Prizes are awarded for matching 2, 3, 4, 5, 5 and the bonus ball or 6
numbers. Write a program to simulate the National Lottery, outputting from 1,000,000 draws how
many times the player won each of the prizes. Use your program to prove the odds of winning the
jackpot of 6 numbers is 1 : 45,057,474.
The game is now unbalanced because it is easier to score points than to pig out or score a sider.
Change the balance of the game so it remains a challenge. Generate a higher random number and
use a greater or lesser range of numbers to represent each position.
Pass the Pigs challenge part 3
Create a two player version of the game where players can choose to bank after each throw, giving
their opponent a chance to throw. Players can continue their go until they pig out or choose to
bank. The first to 100 banked points wins.
Research the full range of scores available in the real game ‘pass the pigs’. Include these in your
game with an appropriate balance of probability.
Battleships challenge
Difficulty:
Requires knowledge of objectives 1-9
Battleships is a game for two players. Each player places four ships on a board but does not reveal
their location to their opponent. Each ship occupies one or more adjacent squares either
horizontally or vertically. Each player takes it in turn to pick a grid reference. The player scores a hit
if the number matches a space occupied by a ship, or a miss if it does not. The player to sink all their
opponents ships first wins.
Quiz challenge
Difficulty:
Q10 is a simple quiz game. Ten random questions are presented to the player one at a time,
together with 4 possible answers. The player has to choose which answer: A, B, C or D is correct.
The computer outputs the correct answer after the player has answered.
Create the following sample quiz file containing two questions in Notepad and save it in a folder for
your new quiz program. Make sure you name it questions.txt
Note the file contains the question, the four possible answers followed by the correct answer.
Create the quiz program to use this file.
The program outputs if the user got the question right or wrong.
The program keeps score and outputs the score to the user.
Modify the program to work for ten questions. Use a loop to show the questions one at a
time, you don’t need to duplicate the code!
The program shows the question number 1-10.
The player is only allowed to answer the next question if they got the previous one correct.
When an incorrect answer is given the quiz ends.
The program picks a random set of questions stored in different files.
The program prevents an illegal data entry. Only characters A-D are accepted.
Till challenge
Difficulty:
Using the product catalogue program, create a program to meet the following specification:
1. A till can be put into ‘admin’ or ‘trading mode’.
2. In the trading mode, the user can perform the following operations:
a. Enter a product code. The product is found and the description and price is
displayed.
b. The price of the product is added to a sub-total.
c. When a product code is not entered, the total is shown.
d. The user enters how much money was given and the change is shown.
e. A new set of transactions then begins.
3. In the admin mode, the user can perform the following operations:
a. View the product catalogue
b. Add a new product
c. Edit a product
d. Delete a product