More results...

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

Traffic Lights Controller using Logic Gates

In this challenge, we will design, create and test a logic gates circuit to control a traffic lights made of 3 LEDs (Red Amber Green). This challenge is designed to be completed with a logic board such as the Logic & Arithmetic board designed by the University of Southampton and the UK Electronic Skills Foundation. You will be able to complete the circuit with just the Logic & Arithmetic board. However if you have access to breadboards and LEDs you will be able to create your own Red Amber Green traffic lights for a more realistic output.

Alternatively, if you do not have access to a physical kit, you can still complete these challenges using our online logic gates circuit simulator

Traffic Lights Sequence

A UK Traffic Lights follows a sequence of four different states:
traffic-light-sequence

In order to design a logic gates circuit for our traffic lights system we will need a circuit with two inputs (J and K) and 3 outputs (X, Y and Z). Our two inputs will give 4 different states to our circuit: 00, 01, 10 and 11. The following diagram shows the expected outputs for 4 possible states (input patterns):
traffic-lights-sequence-2-inputs-3-outputs

Truth Table?

Your first task is to use the above diagram to complete the Truth Table for our Traffic Light Controller system:

Input J Input K Output X (Red) Output Y (Amber) Output Z (Green)
0 0
0 1
1 0
1 1

Logic Gates Diagrams

Using the information from the completed Truth table we can then work out the logic gates circuits needed to control each output based on the two inputs J and K.
You can try to create this diagrams by yourself using logic.ly or our online Logic Gates Diagram designer tool.

Here are the individual diagrams:
Output X: Red Light:
Red-Light-Logic-gates-Diagram
Output Y: Red Light:
Amber-Light-Logic-Gates-Diagram
Output Z: Red Light:
Green-Light-Logic-Gates-Diagram

All three diagrams can then be combined into a single diagram:
Traffic-Lights-Controller-Logic-Gates-Diagram

You can now recreate this circuit with your logic board:
traffic-light-controller-logic-board-xyz

Using RGB LEDs

The following diagram shows you how to connect your logic board to 3 LEDs on a breadboard.
traffic-light-controller-logic-board-leds

Be careful when connecting your LEDs to detect where the anode and the cathode are on each LED:
LED

Using Lego bricks…

You can also create your own traffic lights using Lego bricks and control them with your logic board!
lego-traffic-light-front
lego-traffic-light-back
lego-led


Traffic Light Sequence using Logic Gates

By combining the above circuit with a 2-bit counter circuit, we can create a fully animated traffic light sequence. Click on the diagram below to test this circuit:

Tagged with: ,

Comparison Operators using Logic Gates

This set of challenges is designed to be completed with a logic board such as the Logic & Arithmetic board designed by the University of Southampton and the UK Electronic Skills Foundation.

Alternatively, if you do not have access to a physical kit, you can still complete these challenges using our online logic gates circuit simulator.

J==K? Comparing if two inputs are equal

The following diagram is used to compare if two inputs are the same. The output (X) should be on if both inputs J and K are set to O or both inputs are set to 1. This circuit is used to implement the comparison operator == (“is equal to”).

logic-board-equal-to-operator

Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1

J<K? Less than operator

The following diagram is used to compare if input J is strictly lower than input K. The output (X) should be on if so (e.g. when J = 0 and K = 1). This circuit is used to implement the comparison operator < (“is less than”).

logic-board-less-than-operator

Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1

J>K? Greater than operator

The following diagram is used to compare if input J is strictly greater than input K. The output (X) should be on if so (e.g. when J = 1 and K = 0). This circuit is used to implement the comparison operator > (“is greater than”).

logic-board-greater-than-operator

Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1

1-bit magnitude comparator

By combining all three logic gates circuits into one, we can create a 1-bit magnitude comparator that takes two inputs (J and K) and produces three outputs:

  • X = (J < K)
  • Y = (J == K)
  • Z = (J > K)

Here is the logic gates diagram for this comparator. You can recreate this circuit and test it on your logic board.
logic-board-binary-comparator
comparisons-operators-equal-less-greater

Truth Table:

Input J Input K Output X
J < K ?
Output Y
J == K ?
Output Z
J > K ?
0 0
0 1
1 0
1 1

Extension Task: !=, <= and >= Comparison Operators

comparison-operators
How could you combine and tweak the above diagrams to create logic gates circuits to implement the following comparison operators:

  • “is not equal to” (e.g. J != K)
  • “is lower than or equal to” (e.g. J <= K)
  • “is greater than or equal to” (e.g. J >= K).

Design your circuits, then recreate them and test them on the logic board to see if they “behave” as you would expect!

Find out more…

You can find out more about binary comparators on the following pages:

Tagged with: ,

Logic Gates Circuits

This set of challenges is designed to be completed with a logic board such as the Logic & Arithmetic board designed by the University of Southampton and the UK Electronic Skills Foundation.

Alternatively, if you do not have access to a physical kit, you can still complete these challenges using our online logic gates circuit simulator

Step 1: The Main Logic Gates

For each of the main logic gates, recreate the circuit as it appears on the diagram. Then use your circuit to compete the truth table for the logic gate.

NOT GateAND GateOR GateXOR GateNAND GateNOR Gate
logic-board-not-gate
Truth Table:

Input J Output X
0
1
logic-board-and-gate
Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1
logic-board-or-gate
Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1
logic-board-xor-gate
Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1
logic-board-nand-gate
Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1
logic-board-nor-gate
Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1

Step 2: Logic Gates Circuits

By combining multiple logic gates together you can create a circuit that will “behave” a certain way. To record how the circuit “behaves” for any given set of inputs we use a Truth Table. For instance you can complete the Truth table for the following circuit:

Logic Gates Circuit
logic-board-circuit-1
Truth Table:

Input J Input K Input L Output X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Step 3: Logic Problems

Your task is to create and test a logic gate circuit for each of the given problems:

Car LightBurglar AlarmSmartphone Ringtone
car-3-doors
A small car has 3 doors: 2 front doors and a hatchback. The internal light of the car is on when any of the car doors is open.

Create and test a logic gates circuit to control the internal light (X) of the car based on whether a door (J, K or L) is open (1) or closed (0).

Input J Input K Input L Output X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
burglar-alarmA burglar alarm has three inputs:

  • Input J: Whether the burglar alarm is activated (1) or not (0).
  • Input K: A motion sensor can detect movement (1) or not (0).
  • Input L: A door sensor can detect if the front door is open (1) or is closed (0).

The alarm siren (X) should be on if the alarm is activated and the motion sensor detects a movement or the door sensor detects that the door is open.

Create and test a logic gates circuit to control the siren of this burglar alarm based on the three inputs J,K and L.

Input J Input K Input L Output X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
incoming-call
A smartphone ringtone is played only if:

  • The phone is receiving an incoming call. (input J = 1)
  • The phone sound is on. (input K = 1)
  • The phone is not on airplane mode. (input L = 0)

Create and test a logic gates circuit to control whether the ringtone of a smartphone is on (X=1) or not (X=0) based on the three inputs J, K, L.

Input J Input K Input L Output X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Extension Task: The Mystery Gate!

Mystery Gate
logic-gates-simplify-circuit
The above logic gates circuit can be replaced by one single logic gate! Recreate this circuit on your logic board to test it and complete its truth table. Then find out what logic gate has the same truth table as this complex circuit.
Truth Table:

Input J Input K Output X
0 0
0 1
1 0
1 1

Logic Gate:

Tagged with: ,

Performance Modelling & Data Visualisation – Q&A

Question 1[2 marks]
road-network A small town wants to improve the traffic within the town centre at peak time. They are considering using a synchronised traffic lights system to fluidify the traffic. But before replacing all existing traffic lights and installing new ones, they would like to use some performance modelling system to evaluate the impact the new traffic lights could have on the traffic.

A graphic designer has produced the following map of the town centre. This map will be used for the main screen of the performance modelling system.

Explain why the above map is an abstraction of the town centre.
Question 2[6 marks]
Describe how the new performance modelling system could use different data visualisation techniques to represent key information about the traffic in the town centre.
Question 3[6 marks]
Evaluate the benefits and limitations for the town to use a performance modelling system in this context?
Save / Share Answers as a link
unlock-access

Solution...

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

Recursive vs. Iterative Algorithm – Q&A

Question 1[2 marks]
For this question, we are looking at an algorithm used to implement the divisibility rule for 3 which states that:

A number is divisible by 3 if the sum of all its digits is divisible by 3.

Let’s look at the following example: is 378 divisible by 3? divisibility-rule-for-3 Here is the Python code for our recursive algorithm:
def isDivisibleByThree(n):
   sum = 0
   for digit in str(n):
     sum = sum + int(digit)
   
   if sum>=10:
     return isDivisibleByThree(sum)
   else:   
     if sum==3 or sum==6 or sum==9:
       return True
     else:
       return False
       
number = int(input("Type a number"))
if isDivisibleByThree(number)==True:
  print("This number is divisible by 3.")
else: 
  print("This number is not divisible by 3.")
Explain why the above code can be described as being a recursive algorithm? State on which line of this code does the recursion occur?
Question 2[4 marks]
Trace this algorithm if the user enters the value 8479
Question 3[4 marks]
Rewrite the function isDivisibleByThree() using an iterative approach instead of a recursive approach.
Save / Share Answers as a link
unlock-access

Solution...

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

File Size Calculations – Q&A

Question 1[3 marks]

text-file-estimate
How many of the above text files can we store on a 1.44MB floppy disk?

Each text file contains 6,000 characters and is encoded using ASCII: 8 bits per character.




Question 2[3 marks]

picture-file-estimate
I have 3,000 pictures on my 32GB micro SD card. How much free space is there left on this SD card?

Each picture file has a width of 1920px, a height of 1080px and a colour depth of 24 bits.




Question 3[4 marks]

sound-file-estimate
I have selected 20 sound files to burn on a CD (700MB). How many extra sound files can I add to this CD?

Each sound file has a sample rate of 44.1kHz, a bit depth of 16-bits and lasts 3 minutes and 30 seconds.





Save / Share Answers as a link

unlock-access

Solution...

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


Tagged with:

OOP – Inheritance – Q&A

Question 1[2 marks]
Class File:​
   private filename​
   
   //Constructor for the File class
   procedure new(strFilename):​
      filename = strFilename​

   public procedure rename(strFilename)​
      if strfilename!="":​
         filename = strFilename​

Class MP3 inherits File:​
  private title​
  private artist​
  private duration​

  //Constructor for the MP3 class
  procedure new(strFilename, strTitle, strArtist, intDuration):​
     super.new(strfilename)​
     title = strTitle       ​
     artist = strArtist​
     duration = strDuration​

  public function getDuration():​
     min = duration // 60​
     sec = duration % 60​
     return (str(min) + ":" + str(sec))

What code would you write to instantiate one new MP3 object called topTrack for the latest 3 minutes 12 seconds song “Shivers” from Ed Sheeran?




Question 2[4 marks]

What are all the methods and properties of the MP3 class?




Question 3[4 marks]

Explain, using an example from this code, what is meant by inheritance?





Save / Share Answers as a link

unlock-access

Solution...

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


Tagged with: , ,

OOP – Encapsulation – Q&A

Question 1[2 marks]
class Padlock:
  private key
  private locked
  
  //Constructor for the Padlock class:
  procedure new(str_key,bool_locked):
    key = str_key       
    locked = bool_locked  
    
  public function unlock(combination):
    if combination==key:
       locked = False
       return True
    else:
      return False
      
  public procedure lock():
    locked = True
    
  public function getKey():
    return key
    
  public function setKey(combination):
    if length(combination)==4:
      key = combination
      return True
    else:
      return False
What code would you write to instantiate two new padlocks: One called bikeLock that is already locked with a combination of 4321 and one called gardenShedLock that is unlocked with a combination of 1234?
Question 2[4 marks]
Explain using an example from the above code for the Padlock class, what is meant by encapsulation.
Save / Share Answers as a link
unlock-access

Solution...

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

Maths Puzzles…

The aim of this challenge is to write a few algorithms to solve the following Maths puzzles:

In order to solve these puzzles, we will use an iterative approach using nested loops to test all possible combinations of two numbers until we find a match.

You will first look at the code used to solve the following puzzle and then tweak this code to solve the puzzles listed above.
maths-puzzle

Iterative Approach using nested loops…

Here is our code based on nested loops to test all possible pairs of numbers between 0 and 1,000.

unlock-access

Solution...

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


Brunel’s Engineering Algorithms

brunel-topper-hatIsambard Kingdom Brunel (1806-1859) was an English civil engineer who is considered one of the greatest figures of the Industrial Revolution. Brunel achieved many engineering firsts thanks to his hard-work, his engineering knowledge, his innovative mind and his renowned problem solving skills. Some of his achievements include assisting in the building of the first tunnel under the River Thames, the design & development of the SS Great Britain, the largest ship ever built at the time: launched in 1843 the SS Great Britain was the first propeller-driven, ocean-liner ship with an iron hull. Brunel also worked on many architectural projects and viaducts when designing the Great Western Railway (GWR) linking Bristol to London. One of his major project, who was fully completed five years after his death, is the famous Clifton Suspension Bridge over the river Avon in Bristol, UK.

In this set of challenges, we are going to write four short algorithms that could have helped Brunel on his engineering projects. Obviously, computers did not exist in Brunel’s time, but the mathematical concepts used by these algorithms were for sure known and heavily used in Brunel’s engineering calculations. You can use our online Python IDE to write your algorithms/functions in Python.

Algorithm #1: Propeller Inner Angle

When Brunel worked on the design and construction of the SS Great Britain ship, most engine powered ships of the time used paddle wheels. His first design for this large iron hull ship was also based on using paddle wheels on both sides of the hull, however Brunel soon found out that using a propeller would be more effective and therefore he changed his design halfway through the construction stage! Once the decision was approved, one of Brunel’s next decisions was to choose how many blades to use for the propeller.

To assist him with the technical drawing of the propeller, Brunel used the following formula:
propeller-inner-angle-formula

Your task is to write a function called calculateAngle() that takes one parameter, the number of blades of a propeller (as a positive integer value). Your function will calculate and return the inner angle between two adjacent blades (in degrees).

You will then be able to complete the following test plan to check that your function is working as expected:

Test #   Input Value:
Number of blades
Expected Output Actual Output
#1 propeller-2-blades 2 180°
#2 propeller-3-blades 3 120°
#3

propeller-4-blades 4 90°
#4 propeller-6-blades📷 6 60°

Algorithm #2: Viaduct Arches

A viaduct is a specific type of bridge that consists of a series of arches, piers or columns supporting a long elevated railway or road. When working on the Great Western Railway (GWR) linking Bristol to London, Brunel designed several viaducts, each with a different length, height and number of arches. The Wharncliffe viaduct 📷 is a great example of his work. Built in 1837, it was the first railway viaduct to be built with hollow piers. It is 270 meters long and consists of eight arches.


Supposing that each arch has the same width, we can calculate the width of an arch as follows:
viaduct-formula

Your task is to write a function called calculateArchWidth() that takes two parameters, the length of the viaduct in meters and the number of arches (both parameters being given as positive integers). Your function will calculate and return the width of an arch.

You can test your algorithm using the following test plan:

Test #   Input Value: Expected Output Actual Output
#1 Wharncliffe Viaduct 📷 Viaduct Length: 270m
Number of Arches: 8
Arch width: 33.75m
#2 Carnon Viaduct 📷 Viaduct Length: 230m
Number of Arches: 9
Arch width: 25.55m

Algorithm #3: Railway Slope

When designing the Great Western Railway (GWR), one of the main objectives of Brunel was to design a fairly straight route as level as possible in order to promote high speed travel on the line. To do so Brunel had to estimate the percent slope (gradient) of every section of the route to avoid steep slops.

Here is the formula that Brunel used to calculate the percent slope of every section of his planned route:
railway-percent-slope-formula

Your task is to write a function called calculatePercentSlope() that takes two parameters: delta_x (Δx) and delta_h (Δh), the difference in coordinates and altitudes between the starting and ending position of a section. Your function will use these two parameters to calculate and return the percent slope of the section.
You can test your algorithm using the following test plan:

Test #   Input Value: Expected Output Actual Output
#1 Section 1 Δx = 800m
Δh = 32m
Percent Slope: 4%
#2 Section 2 Δx = 500m
Δh = 60m
Percent Slope: 12%
#3 Section 2 Δx = 750m
Δh = 45m
Percent Slope: 6%

Algorithm #4: Suspension Bridge Arc Length

One of Brunel’s most famous project is the Clifton Suspension Bridge, Bristol’s most impressive structure. He started to design this project at the age of 24. The bridge took 33 years to complete!

clifton-suspension-bridge

One of the mathematical puzzle that Brunel had to solve, was to estimate the length of the main arc of the suspension bridge. This arc consists of wrought iron chains to support the load of the main deck as well as the extra load due to the traffic across the bridge. The arc joins the two towers on each side of the river Avon. The two towers are separated by 214 meters and are rising 26m above deck level. The deck itself is 75m above the high water mark!

The following mathematical formulas can be used to calculate the arc length based on the distance between the two towers (l) and the height of each tower (from the deck level) (h)

suspension-bridge-arc-length-formula
Your task is to write a function called calculateArcLength() that takes two parameters: the length (l) and the height (from the deck level) (h) of the suspension bridge. Your function will use these two parameters to calculate and return the length or the arc of the bridge.

You can test your algorithm using the following test plan:

Test #   Input Value: Expected Output Actual Output
#1 Clifton Suspension Bridge length = 214m
height = 26m
Arc Length: 222m

To find out more about Brunel‘s work visit the SS Great Britain museum in Bristol, UK.

unlock-access

Solution...

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


Tagged with: ,