Basic Algorithms
Challenges
Challenge 1
Write an algorithm/code that will output your name, age and tutor group. (3 marks)
Guidance:
- 1 mark for outputting the name.
- 1 mark for outputting the age.
- 1 mark for outputting the tutor group.
Solution:
Challenge 2
Write an algorithm/code that will store the following values in the following variables: (4 marks)
- Name = “Bob”
- Age = “15”
- Tutor_Group = 10TFQ
These values will then be output into the main program.
Guidance:
- 1 mark for writing out the correct variables with its associated values
- 1 mark for correct output of Name
- 1 mark for correct output of Age
- 1 mark for correct output of Tutor Group
Solution:
Challenge 3
Write an algorithm/code that will ask the user to input their name, age and tutor group which are then output
into the main program. (4 marks)
Guidance:
- 1 mark for correct input of Name.
- 1 mark for correct input of Age
- 1 mark for correct input of Tutor Group
- 1 mark for correct output of all three.
Solution:
Challenge 4
Write an algorithm/code that will ask the user to input their name, age and tutor group which are then
outputted into the main program and on the same line. (4 marks)
The output should look like this:
- Hello my name is Bob, I’m 15 years old and my tutor group is 10TFQ
Guidance:
- 1 mark for correct input of Name.
- 1 mark for correct input of Age
- 1 mark for correct input of Tutor Group
- 1 mark for correct output of all three in an appropriate message.
Solution:
Challenge 5
Write an algorithm/code that will ask the user to input their name, age and tutor group which are then
outputted into the main program and on separate lines. (4 marks)
The output should look like this:
- Hello my name is Bob
- I’m 15 years old.
- My tutor group is 10TFQ
Guidance:
- 1 mark for all three inputs.
- 1 mark for each correct message (3 in total)
Solution:
Challenge 6
Write an algorithm that will ask the user to input their name, tutor group, year of birth and current year. The
name and tutor group are outputted into the main program along with the age. (5 marks)
The age will be calculated by using year of birth and current year. The output should look like this:
- Hello my name is Bob
- My tutor group is 10TFQ
- I’m 15 years old.
G
u
i
d
a
n
c
e
:
S
o
l
u
t
i
o
n
:
Challenge 7
Write an algorithm/code that will allow the user to input two numbers and perform addition, subtraction,
division and multiplication on them. The final results of each should be output in the main program (6 marks)
It should look like this:
- 5 + 5 = 10
- 5–5=0
- 5 * 5 = 25
- 5/5=1
Guidance:
- 1 mark for inputting two numbers.
- 1 mark for correct use of addition
- 1 mark for correct use of subtraction
- 1 mark for correct use of multiplication
- 1 mark for correct use of division
- 1 mark for outputting the answers in the appropriate format.
Solution:
Challenge 8
Write an algorithm that will store the prices of a Snickers chocolate bar which is 75p. It will allow the user to
input how many bars they would like and how much money they will pay. The program should include a line of
code that will calculate the change to be given back to the customer. (5 marks)
It should look like this:
- Thank you, you have ordered 3 bars.
- The total cost will be £2.25
- Thank you, I have received £5.
- You will now receive £2.75 in change.
Guidance:
- 1 mark for storing the chocolate bar in an appropriately named variable.
- 1 mark for correct input for number of bars
- 1 mark for correct input of money paid by the customer
- 1 mark for correct formula that calculates the change
- 1 mark for outputting in the same format as shown above.
Solution:
Challenge 9
When an object moves in a straight line with a constant acceleration, you can calculate its acceleration if you
know how much its velocity changes and how long this takes.
The formula that calculates acceleration is: a = (v-u) ÷ t.
Write an algorithm/code that will allow the user to input final velocity in m/s (v), initial velocity in m/s (u) and
time in seconds (t). A formula should then be used to calculate acceleration and then output into the main
program. (5 marks)
Guidance:
- 1 mark for correct input of final velocity
- 1 mark for correct input of initial velocity
- 1 mark for correct input of time in seconds
- 1 mark for correct formula used to calculate acceleration.
- 1 mark for outputting the answer in an appropriate message.
Solution:
Challenge 10
Write an algorithm that will allow the user to input two numbers. The program should then include two
formulas that will divide the two numbers; one showing the real value and one that rounds the answer to the
nearest number. (4 marks)
It could look like this:
- You have entered the number 12
- You have entered the number 5
- 12 divided by 5 is 2.4 and can be rounded to 2.
Guidance:
- 1 mark for both inputs
- 1 mark for correct use of integer division
- 1 mark for correct use of real division
- 1 mark for outputting the answer in an appropriate message.
Solution:
Challenge 11
Write an algorithm that will allow the user to input two numbers. The program should then include two
formulas that will divide the two numbers, one showing how many times that the second number goes into the
first number and the second one should show the remainder (what’s left over) (4 marks)
It could look like this:
- You have entered the number 12
- You have entered the number 5
- 5 goes into 12, 2 times with 2 left over.
Guidance:
- 1 mark for both inputs
- 1 mark for correct use of division
- 1 mark for correct use of modulus
- 1 mark for outputting the answer in an appropriate message.
Solution:
Challenge 12:
Write an algorithm that will ask the user to input two numbers and use exponentiation to calculate the answer.
Guidance:
- 1 mark for both inputs
- 1 mark for correct use of exponentiation.
- 1 mark for outputting the answer in an appropriate message.
Solution: