More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Playing Cards Sorting Algorithm

The aim of this online activity is to sort a set of 8 playing cards randomly picked from a deck of cards based on the following rules:

  • The cards need to be sorted in ascending order of their values. For the purpose of this task, an Ace will be the lowest value (1) whereas a King will be the highest value (13).
  • In order reveal a card you need to click on it to flip it. However you will only be able to reveal two cards at a time.
  • Should you decide to swap two cards, you will need to drag one of the card on top of the other card. Both cards will then swap position.
  • If you believe a card is in position, you can tick the checkbox underneath it.
  • If you believe all 8 cards are sorted, you can click on the “Check if cards are sorted” button. If they are in the correct order, from lowest to largest value, all 8 cards will be revealed.
  • At anytime, you can start this task again with a fresh set of cards by clicking the “New Cards” button.

Your aim is to find a method (algorithm) that works for you and enable you to sort all the cards with a minimum number of swaps.

Playing Cards Sorting ChallengeOpen in New Window

Sorting Algorithms

They are a range of different algorithms that can be used for a computer to sort a list of values. You can investigate some of the most widely used sorting algorithms using the following blog posts:

Logic Gates Circuits used in a Theme Park

In this set of challenges, you will design and test some logic gates circuits to control different automated systems used to control the following rides of a Theme park:

  • Ferris Wheel
  • Drop Tower
  • Roller Coaster
Ferris WheelDrop TowerRoller Coaster

Ferris Wheel

A Ferris Wheel automated control system controls whether the wheel should be spinning or should be stopped.

The automated system is based on the following inputs:

  • A main switch is controlled by the main operator to decide if the wheel is in operating (spinning) or not.
    • If the switch is on, the wheel is spinning
    • If the switch is off, the wheel is not spinning, allowing for passengers to load/unload a cabin.
  • Weight sensors are also used in each of the cabins of this Ferris wheel. A sensor is “on” if the cabin it’s on is overloaded (too heavy). If any of the sensors is on, the wheel is automatically stopped. For the purpose of this task, we will assume that our Ferris Wheel only contains 4 cabins. We will therefore only use 4 sensors. In reality, more sensors would be needed.

Use our logic gates circuit simulator to design and test a circuit for the Ferris Wheel automated control system. (Click on picture below)

Drop Tower

To join the queue to get on board the Drop Tower, the passengers must comply with some safety rules. A control panel is available to control a gate to let a passenger join the queue. The control panel has 3 switches as follows:

  • Switch A to indicate whether the passenger is 12 or over.
  • Switch B to indicate whether the passenger is at least 4-feet tall.
  • Switch C to indicate whether the passenger is accompanied by an adult.

For the gate to open to let the passenger join the queue for the ride, the rules are as follow:

  • The passenger must be at least 4-feet tall.
  • The passenger must either be 12 or over and if not, they must be accompanied by an adult.

Click on the picture below to design and test the logic gates circuit to control the gate, so that if a passenger is allowed to get on board the Drop Tower, the gate is “on”, but if not the gate is “off“.

Roller Coaster

An emergency stopping system controls whether a signal should be sent to the train of a roller coaster to stop it, in case of an emergency. The system is based on the following inputs:

  • A main switch is controlled by the main operator to start (switch is “on”) or stop (“off”) the roller coaster. There are however only three locations on the track where it is safe for the roller coaster to be stopped.
  • There are 3 sensors on the track, one on each of these 3 locations. The sensor is “on” if it detects the train at this given location. At least one of the three sensors must be on for the train to be stopped.
  • A safety guard sensor is also used to detect if any of the safety guards are not securely locked in. When all safety guards are locked in, the sensor is “on”.
    If any of the safety guards are unlocked, the sensor is “off”: In this case, the train should automatically be stopped provided that the train is at one of the three safe locations to be stopped.

Use our logic gates circuit simulator to design and test a circuit for the Roller Coaster Emergency Stopping System.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

Code Maintainability Q&A

Question 1[4 marks]



The two Python scripts above were created by an IT manager of a school and are performing exactly the same task: to generate a username based on the student’s firstname, lastname and year group. Compare both of these scripts and identify what was done to the code to make it easier to understand, maintain and re-use in future projects?




Question 2[2 marks]

The IT manager would like to make this program more robust by adding a validation check on the year group. The school only has students in year 7 to year 13. How could the IT manager change the code above to make sure the user can only enter a value between 7 and 13 for the year group?




Question 3[4 marks]

The IT manager would like to test his new validation check on the year group. Identify 4 pieces of test data that the IT manager should use to perform a normal/valid test, an invalid test, a boundary test and an erroneous test?

Normal/Valid Test Data:
Invalid Test Data:
Boundary Test Data:
Erroneous Test Data:



The Marauder’s Map Coding Challenges

Welcome to Hogwarts, school of witchcraft and wizardry! For this set of challenges, you will be helping the famous wizard, Harry Potter, to recover all of his magical possessions.

Effectively, it would seem that a malevolent wizard did cast a spell on Harry Potter’s belongings. As a consequence, twelve of Harry Potter’s favourite magical objects have been buried on the school premises, within or around Hogwarts Castle.

Harry found a note on his bed containing 12 encoded messages that look like some kind of magical algorithms. He believes that he could use Professor Dumbledore’s Marauder’s Map to help him locate his 12 magical objects. However, Harry needs your help to decode these algorithms. Will you be able to use the Marauder’s Map and decode the 12 algorithms to locate all of Harry Potter’s magical artefacts?

The Marauder’s Map Coding ChallengesOpen in New Window
The Marauder’s Map Coding ChallengesOpen in New Window

The Moroccan Spices Box Set Puzzle

In the heart of the medina of Marrakech, you will find one of the largest and most colourful souks in Morocco. In this souk, you will find merchants selling traditional clothing, multicoloured carpets, pottery, jewellery, antiques, lanterns, spices, etc. On the spice square, Halim, a merchant of Moroccan spices, would like to sell different box sets of jars containing various spices. Halim has a collection of 10 jars and would like to create three box sets of exactly 250g each.

Could you help Halim create these three box sets using the following 10 jars. Each set must contain exactly 250g of spices. (Drag and drop the following jars to create three groups)

View Solution
There are more than one solution to this puzzle. Here is one possible solution:

Python Challenge

To help Halim to create similar box sets in the future, we would like to create a Python algorithm that suggests a possible solution for any given set of jars.

We will use a list to store the collection of jars available. For instance, using the current set of 10 jars, our list would be as follows:
jars = [150,20,20,10,80,130,110,90,100,40]

The aim of this challenge is to use a backtracking / recursive algorithm to work out a possible solution for this puzzle by creating three lists of jars, using the values from the above jars list to create 3 box sets of exactly 250g each.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

HTML and CSS Quizzes

Do you know your HTML tags used to create a webpage? Do you know how to use CSS to customise the look and feel of all the elements of this page? See how many HTML tags and how many CSS properties you can list in under 5 minutes by completing the following two quizzes.

To learn more about HTML and CSS you can use the tutorials from w3schools:

Tagged with: ,

Standard Deviation Algorithm

In statistics, given a set list of numbers, the standard deviation is a measure of the amount of variation or dispersion within the set.

A low standard deviation indicates that the values tend to be close to the mean value of the set.
A high standard deviation indicates that the values are spread out over a wider range.

The formula to calculate the standard deviation for a given set of numbers is as follows:

Where x represents the mean value of the set and n represents the number of values in the set.

Your task is to design an algorithm for a function called standardDeviation() that takes one parameter: a list of integer values. The list can be of any length. Your function will calculate and return the standard deviation for this given list.

Python Code

We have started the code for you by creating a function called inputList() that lets the user input any list of numbers, one number at a time. Your task is now to add the code for the standardDeviation() function.

Test Plan

Test # Input Values Expected Output Actual Output
#1 7,14,9,21,32,15 8.3199893162325
#2 23,101,52,48,107 32.480147782915
#3 10,40 15
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

The Jorvik Viking Settlement​

From around A.D. 800 to the 11th century, a large number of Scandinavians Vikings left their homelands to seek their fortunes on the east coast of England. These seafaring warriors ransacked different coastal sites from Northembria to East Anglia. In 866, they invaded the city of York which, after being renamed Jorvik, became their capital.​

​Most of their constructions was made of wood, hence there are not so many vestiges left of their occupation. Vikings invaded the East coast of England after crossing the North Sea on long wooden ships. One of their traditions was to bury these ships in the ground to create a burial site for their dead.​

While excavating a site under the Cathedral of York, a team of archaeologists have recently found a complex system of 12 locking compartments, carved directly in stone. They believe each compartment contains a Viking shield and that each shield has a symbol engraved on it. By accessing these 12 symbols, they believe they could reveal the location of a ship burial site where Ragnar Lothbrok, one of the most famous Viking warrior, is buried alongside his undiscovered treasure of inestimable value.​

Each locking mechanism consists of two sliders. For each mechanism, a diagram has also been carved in the stone which, we believe, provides the key to unlock the compartment. It is essential to open these compartments by finding the correct position of the sliders, as trying to break the mechanism itself to open the compartment would damage its content and would prevent the archaeologists from revealing the code engraved on each shield.​

The team of archaeologists is asking your help to help them unlock the 12 compartments and reveal the location of Ragnar Lothbrok’s treasure!​
The Jorvik Viking SettlementOpen in New Window
The Jorvik Viking SettlementOpen in New Window

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Countries of Africa

Can you name all of the 54 countries of Africa?

In this challenge we will write a Python script to create a quiz where we ask the user to guess as many African countries as possible. The player will score one point per correct country.

Using a list in Python

Our Python program will use a list to store all 54 countries.

countries = [“Algeria”, “Angola”, “Benin”, “Botswana”, “Burkina Faso”, “Burundi”, “Cabo Verde”, “Cameroon”, “Central African Republic”, “Chad”, “Comoros”, “Ivory Coast”, “Djibouti”, “Democratic Republic of the Congo”, “Egypt”, “Equatorial Guinea”, “Eritrea”, “Eswatini”, “Ethiopia”, “Gabon”, “Gambia”, “Ghana”, “Guinea”, “Guinea-Bissau”, “Kenya”, “Lesotho”, “Liberia”, “Libya”, “Madagascar”, “Malawi”, “Mali”, “Mauritania”, “Mauritius”, “Morocco”, “Mozambique”, “Namibia”, “Niger”, “Nigeria”, “Republic of the Congo”, “Rwanda”, “Sao Tome & Principe”, “Senegal”, “Seychelles”, “Sierra Leone”, “Somalia”, “South Africa”, “South Sudan”, “Sudan”, “Tanzania”, “Togo”, “Tunisia”, “Uganda”, “Zambia”, “Zimbabwe”]

To check how many items (countries) are in the list, we can use the len() function:

numberOfCountries = len(countries)
print("There are " + str(numberOfCountries) + " countries in Africa!")

To check if a country is in the list we can use the keyword in as follows:

if "Kenya" in countries:
   print("Kenya is in Africa!")

To remove a country from the list, we can use the remove() function. For instance is the user has named a country which is in the list, we can remove this country from the list.

if "Kenya" in countries:
   countries.remove("Kenya")

Flowchart

Below is the full flowchart for our Python quiz: (Click on flowchart to zoom in)

Python Code

We have started the code, you task is to complete the code in the trinket window below:

Extension Task

Amend this code to give the player three lives. For each invalid answer, the player should lose a life. The game should stop and display a game over message when the player has found all 54 countries or when they have lost their 3 lives.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Let’s Build a Castle

In this challenge we are going to build different medieval castles by customising some Python code.

Our first castle is already made for us and looks as follows:

You can see, in the trinket window below, the Python code used to create this castle.

The code uses a range of pre-defined functions to draw the different building blocks of the castle (walls, towers, doors, flags and loopholes). These functions can be accessed in the extra file (tab) called shapes.py. However for the purpose of this challenge, you will not need to access the code of these functions.

The main functions that you will have to reuse to cutomise the look and feel of your castle are:

  • drawWall()
  • drawTower()
  • drawDoor()
  • drawLoophole()
  • drawFlag()

Each of these functions is using some parameters to change the position, width and height of the different building blocks and to change the colour of the flag. Let’s investigate these functions and their parameters.

drawWall()drawTower()drawFlag()drawDoor()drawLoophole()(X,Y) Coordinates?Colour Codes?
The drawWall() function uses the following 6 parameters:

So the following code would be used to create a wall at position (-150,0). The wall would be 300 pixels wide, 150 pixels high and would have battlements (crenellation).

The drawTower() function uses the following 6 parameters:

So the following code would be used to create a tower at position (-100,0). The tower would be 50 pixels wide, 150 pixels high and would have battlements (crenellation).

The drawFlag() function uses the following 6 parameters:So the following code would be used to create a flag at position (120,120). The flag would be 30 pixels wide, 40 pixels high and be of a red colour.
The drawDoor() function uses the following 5 parameters:
So the following code would be used to create a door at position (-100,0). The door would be 50 pixels wide, 150 pixels high.
The drawDoor() function uses the following 5 parameters:
So the following code would be used to create a loophole at position (-100,0). The loophole would be 10 pixels wide, 30 pixels high.

(X,Y) Coordinates?


The canvas we are drawing on (using Python Turtle) is 400 pixels wide by 400 pixels high.
Look at the canvas below to understand how (x,y) coordinates work:


Colour Codes


#FF0000#FFFF00#0000AA#00AA00

Python Code

Here is the Python code to create the castle.

Your Task

Your task is to edit the code from line 16 to 27 to re-create the following castles. To do so you will have to tweak the parameters of the functions used to create the castle. You may also need to remove or add some extra lines of code to add extra elements (towers, flags, loopholes, etc…)

Extension Task

Access the code in the shapes.py file (tab).
Create two more functions as follows:

  • drawSun() to draw a yellow circle at a given (x,y) set of coordinates.
  • drawTree() to draw a tree at a given (x,y) set of coordinates.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: