COMPUTER SCIENCE CAFÉ
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
CODING CHALLENGES | ARRAYS
Enjoy the journey of learning to code, explore and be creative
ON THIS PAGE
CHALLENGE 1 | GUEST LIST
CHALLENGE 2 | GET SORTED
​CHALLENGE 3 | FOOTBALL TEAMS - RANDOM NAME PICKER
CHALLENGE 4 | PLANET DISTANCE
​CHALLENGE 5 | PURCHASE ORDER
​CHALLENGE 6 | MINE FIELD GAME (2D ARRAY)
Picture
SUBSCRIBE FOR SAMPLE SOLUTIONS
ALSO IN THIS TOPIC
LEVEL 1 | GETTING STARTED
 LEVEL 2 | VARIABLES AND USER INTERACTION
LEVEL 3 | DATATYPES AND OPERATORS
 LEVEL 4 | IF STATEMENTS
 LEVEL 5 | LOOPS
YOU ARE HERE | ​LEVEL 6 | ARRAYS / LISTS
LEVEL 7 | FUNCTIONS
LEVEL 8 | ALGORITHM DESIGN
LEVEL 9 | OOP
LEVEL 10 | EXTERNAL DATA HANDLING
TURTLE CHALLENGES
DEBUGGING AND TRACING​
CHALLENGE SOLUTIONS

Picture
​
WATCH THIS VIDEO TO HELP YOU WITH THIS SECTION
Picture
CHALLENGE 1 | GUEST LIST
Jenny is holding a party and what to record the names of people that attend the party so she can organise party games later. she wants to build a program so people can type their names as they enter the party. Jenny wants to print a list at the end of the party with the names of attendees with a number showing the order in which they arrived.
​
Create a program to do the following:

1: Ask each guest for their first name and append to a list that holds guests first names
2: Ask each guest for their last name and append to a list that holds guests last names
3: Give a prompt to allow the guest or Jenny to add another guest or end the entries
4: Output the guest list in a user friendly format, showing a guest number, first name and last name. This output show show one guest per line and each line printed as a single string.
EXAMPLE OUTPUT
Would you like to add a guest Y/N ? Y
Please enter the first name: 
Please enter the last name: 

Would you like to add a guest Y/N ? Y
Please enter the first name: 

Please enter the last name: 

Would you like to add a guest Y/N ? N
Here is the guest list:
1: Jane Hill
​2: Bob Fisher

EXTENSION TASK
When you ask 'Would you like to add a guest Y/N ?', Make your program accept various user entries such as 'Yes', 'yes', 'Y', 'y', 'No', 'no', 'N', 'n'. And ask again if any invalid inout is given.
Picture
CHALLENGE 2 | GET SORTED
Delia has a list of numbers that see wants to to sort, she wants to keep the original list for future reference.
myList = [3,45,2,6,47,87,45,3,5,1,76,45,2,8,38,56,4]
mySortedList = []
​
Without using a built in sort method - create a program to do the following:

1: Create an algorithm to copy the numbers from myList to mySortedList in ascending order
2: After the sort - print both the original list and the sorted list

NOTE: create your own algorithm to do this DO NOT use methods such as the .sort in Python
EXAMPLE OUTPUT
[1,2,2,3,3,4,5,6,38,45,45,45,47,56,76,87]

Picture
​CHALLENGE 3 | FOOTBALL TEAMS
A PE teacher has 22 students in her class and wants to create two football teams with a random name selector.  She wants to play 11 players per side. Here is the list of students in her class.

"Dave","Jasmine","Jona","Bill","Katina","Rob","Bernie","George","Jenny","John","Jill", "Jo","Emma","Eddie","Bob","Jarod","Kylie","Connor","Tracy","Don","Delia","Sam"

Create a program to do the following:

1: Hold all players in a single list.
2: Print the list of players in the class in a user friendly format
3: Ask the teacher if she would like generate two teams at random
4: Create two lists to hold the teams - team1 and team2.
5: Populate the lists with players at random, make sure a player does not get picked twice. NOTE: You should use a random number generator to create random numbers that will reference each index from the list.
6: Print the two team lists in a user friendly way.
EXTENSION TASK:
​Ask the teacher if she is happy with the teams or if she wants to run the random name picker again.
Picture
CHALLENGE 4 | PLANET DISTANCE
planetList = ['Mercury', 'Venus', '50290000','Mercury', 'Earth', '91691000','Mercury',
 'Mars', '170030000','Mercury', 'Jupiter', '720420000','Mercury', 'Saturn',
 '1366690000','Mercury', 'Uranus', '2815640000','Mercury', 'Neptune',
 '4443090000','Venus', 'Earth', '41400000','Venus', 'Mars', '119740000',
 'Venus', 'Jupiter', '670130000','Venus', 'Saturn', '1316400000','Venus',
 'Uranus', '2765350000','Venus', 'Neptune', '4392800000','Earth', 'Mars',
 '78340000','Earth', 'Jupiter', '628730000','Earth', 'Saturn', '1275000000',
 'Earth', 'Uranus', '2723950000','Earth', 'Neptune', '4351400000','Mars',
 'Jupiter', '550390000','Mars', 'Saturn', '1196660000','Mars', 'Uranus',
 '2645610000','Mars', 'Neptune', '4273060000','Jupiter', 'Saturn',
 '646270000','Jupiter', 'Uranus', '2095220000','Jupiter', 'Neptune',
 '3722670000','Saturn', 'Uranus', '1448950000','Saturn', 'Neptune',
 '3076400000','Uranus', 'Neptune', '1627450000']
List thanks to: Distances Between the Planets of the Solar System • The Planets
Using the planet list/array above, create a program that shows the user a list of planets, then asks the user to choose two planets from the list. Output the distance average between the two planets selected
1: Output the name of the 8 planets 
2: Ask the user to choose the start planet
3: Ask the use to enter the destination planet
4: Output the distance between the 2 planet chosen.


EXAMPLE OUTPUT
Please see the planet list below:
1: Mercury
2:Venus
3: Earth
4: Mars
5: Jupiter
6: Saturn
7: Uranus
8: Neptune
Please select he starting planet 1-8: 4
Please select the destination planet 1-8: 3
The Average distance from Mars to Earth is 78340000 
Picture
​CHALLENGE 5 | PURCHASE ORDER
The lists above contain products and the related list contains the price for each product. 
Create a program that:
1: Asks the user what category of product they would like to purchase.
2: Shows the user a list of products and price for each product in their chosen category.
3: Ask the user to select a product
4: Ask the user to enter the quantity they would like to purchase
5: Ask the user if they would like to purchase a related product
5b: IF the user wants a related product then show the product list related to their purchase category
6: Ask the user to enter the quantity they would like to purchase 
7: Calculate the sub total of the purchase made
5: Calculate the tax value at 20%
6: Produce receipt showing
  • The products purchased
  • The sub total for each product
  • The total tax payable
  • The total price payable
​NOTE: All outputs should be in a user friendly string. (use concatenation)

EXAMPLE OUTPUT
Picture
PIRATES AND TREASURE
Motly Deadwood, a mighty pirate is going to sail to find hidden treasure. He and his crew know there are other pirates out there and they want to avoid being raided by these. Can you play the game of chance to help Deadwood navigate to the treasure whilst avoiding landing on Pirates?

TASKS: Create a text-based game:
You are to create a game using a 1d array.

1: Create a 1D array with 11 #s in each index
2: Use a random generator to make 3 of the positions in each index a pirate. Do not display where the pirates are.
3: All other positions in the array should be treasure. Do not display where the treasure is.
4: The player should start in index 0
5: Give the player 100 gold coins at the start of the game
6: Choose a representing character for pirates. P in this example
7: Choose a representing character for treasure. T in this example
8: Allow the user to navigate the array by entering a number/position to move to. 

9: When the user lands on a pirate, deduct 20 gold coins
10: When the user lands on treasure add 10 gold coins
11: Loop the game so the player has 5 moves.

EXTENSION:
use your idea and create the next level.
Picture
​CHALLENGE 6 | MINE FIELD GAME
SCENARIO FOR PLAYER:  
Dangerous dan is at the south end of a mine field and needs to create a path to the other side so villagers in his community can get to the other side (north end). Dangerous dan is hoping for fortune and glory for his efforts and is confident he can navigate the mine field with your help. 

TASKS:
You are to create a game using a 2d array.

1: Create a 2D array with 10 *s in each index
2: Use a random generator to make 3 of the stars in each index a mine. Do not display where the mines are.
3: Choose a representing character for the user. D in this example
4: Allow the user to move round in the array with up, down, left and right controls 

5: Display a character such as a hash tag to trace the users
movements
 

The aim of the game is to move from the bottom row of the array to the top row without hitting a mine. If the user lands on a mine then it is game over.   

EXAMPLE RUNNING PROGRAM:
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
D * * * * * * * * * 
 
WHERE WOULD YOU LIKE TO MOVE UP(U)/DOWN(D)/LEFT(L)/RIGHT(R)? U 
* * * * * * * * * * 
* * * * * * * * * * 
D * * * * * * * * * 
# * * * * * * * * * 
WHERE WOULD YOU LIKE TO MOVE UP(U)/DOWN(D)/LEFT(L)/RIGHT(R)? R 
* * * * * * * * * * 
* * * * * * * * * * 
* M  * * * * * * * * 
* * * * * * * * * * 
GAME OVER – YOU LANDED ON A MINE 

EXTENDED TASK:

1: Add new levels and new features to your game when this first part is complete. 
Picture
Picture
NAVIGATION
LEVEL 1 | GETTING STARTED
LEVEL 2 | VARIABLES AND USER INTERACTION
LEVEL 3 | DATATYPES AND OPERATORS
LEVEL 4 | IF STATEMENTS
LEVEL 5 | LOOPS
​LEVEL 6 | ARRAYS / LISTS
LEVEL 7 | FUNCTIONS
LEVEL 8 | ALGORITHM DESIGN
LEVEL 9 | OOP
LEVEL 10 | EXTERNAL DATA HANDLING
TURTLE CHALLENGES
DEBUGGING AND TRACING​
CHALLENGE SOLUTIONS
Picture
SUGGESTIONS
We would love to hear from you
SUBSCRIBE 
To enjoy more benefits
We hope you find this site useful. If you notice any errors or would like to contribute material then please contact us.