More results...

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

My daily routine

daily-routine

Learning Objectives


When you write lines of code, there are three ways you can control the order these lines will be executed by the computer:

  1. Sequencing: This means that the computer will run your code in order, one line at a time from the top to the bottom of your program. It will start at line 1, then execute line 2 then line 3 and so on till it reaches the last line of your program.
  2. Selection: Sometimes you only want some lines of code to be run only if a condition is met, otherwise you want the computer to ignore these lines and jump over them. This is achieved using IF statements. e.g. If a condition is met then lines 4, 5, 6 are executed otherwise the computer jumps to line 7 without even looking at line 4,5 and 6.
  3. Iteration: Sometimes you want the computer to execute the same lines of code several times. This is done using a loop. There are three types of loops: For loops, while loops and repeat until loops. That’s handy as it enables you not to have to copy the same lines of code many times.

Let’s Get Coding


For this task we are going to write a program that uses sequencing, selection and iteration all in the same program! Our program will be used to print our daily routines on screen over a full week. Look at the code below and try to make sense of how it works. Can you spot where and how sequencing, iteration and selection are used in this code?

Your Task


Your task is to tweak this code to customise your daily routines. Add to it some of the activities or clubs you go to. For instance:

  • Are you going swimming on Tuesdays?
  • Do you play football on Saturdays?
  • Do you go to a Youth Club on Thursdays?
  • Do you play music on Fridays?
  • Is Friday Fish and Chips day?
Tagged with: , ,

Sweet Shop

sweetsHave you ever been in a sweet shop to buy sweets? For this challenge we are going to spend £5 in a sweet shop hence we need to find out how many sweets we can afford. We will want to pick and mix sweets until we have spent all our money.

To help us buy our sweets we are going to write a program that will help us decide how many sweets we can afford while allowing us to pick and mix different types of sweets.

Here are the sweets available in the shop:
sweet-shop-price-list

Here are the main steps of our program which will:

  1. Display a price list of all the sweets available in the shop,
  2. Ask the end-user how much they would like to spend,
  3. Ask the user which sweet they would like to buy and how many of them they would like (A to E),
  4. Allow the user to enter X (instead of the A to E letter for a sweet) to stop buying more sweets,
  5. Check whether the use can afford these and if they can, calculate and display how much money they have left,
  6. Repeat steps 3 to 5 for as long as the user has some money left.

Now let’s see how a flowchart can help us describe these steps further:
sweet-shop-flowchart

Your task:


Use the above flowchart to complete the code below:

unlock-access

Solution...

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

The window cleaner’s quote

window-cleanerA window cleaner uses the following pricing policy to calculate how much to charge for cleaning all the windows of his customer’s dwelling. This pricing policy is based on the number of windows that need to be cleaned and works as follows:

  • All quoted prices include a fixed call out fee of £10,
  • Then, the first five windows are charged at £2 each,
  • The next five windows are charged at £1.50 each,
  • Any additional windows are charged at £1 each.

Your task is to write a computer program that prompts the end-user to enter the number of windows of their dwelling. The program will then calculate the quoted price using the pricing policy described above and display it to the end-user.

Test Plan


Now that you have implemented the cost calculator for the house cleaner, you are going to test your code by completing the following tests: see test plan below. For each test compare the outcome of your program with the expected outcome. If these are different then you’ll need to review and tweak your code.

Test # Input values Expected outcome Actual outcome
1 Number of windows: 3 Cost: £16
2 Number of windows: 5 Cost: £20
3 Number of windows: 7 Cost: £23
4 Number of windows: 9 Cost: £26
5 Number of windows: 10 Cost: £27.50
6 Number of windows: 11 Cost: £28.50
7 Number of windows: 13 Cost: £30.50
8 Number of windows: 15 Cost: £32.50

Extension Task:


At the beginning of the year, the house cleaner wants to attract new customers by offering a 10% discount to all quoted prices.

Adapt your code to include a 10% discount in the quoted price.

Solution



unlock-access

Solution...

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

Gradient Animation

color-gradientIn this challenge we are going to create some animated gradients by progressively changing the colour of the screen from one colour (e.g. red) to another (e.g. yellow).

RGB Colour Codes


Did you know that every colour on the screen can be represented using an RGB code (Red, Green, Blue) code. This code consists of three numbers between 0 and 255, indicating how much red, green and blue are used to recreate the colour.

For instance the RGB code for:

  • Red is (255,0,0)
  • Green is (0,255,0)
  • Blue is (0,0,255)
  • Yellow is (255,255,0)
  • Orange is (255,165,0)

Check the following RGB Color picker to see how RGB codes work:

Learning Objectives


By completing this code we will investigate how for loops work to iterate through the code a fixed number of times.

We will use an increment in our loop that will go up (increment) by 1 after each iteration, to count from 0 to 255. We will see that we can also use a negative step to count down from 255 to 0.

Gradient #1:


Our first animation will be based on the following gradient:
color-gradient-1

It will consist of:

  • 256 frames to shade from red (255,0,0) to yellow (255,255,0)
  • + another 256 frames to shade from yellow (255,255,0) back to red (255,0,0)
  • It will repeat the above steps 3 times so in total will consist of (256 + 256) x 3 = 1536 frames!

Check the code below: If this code does not work in Internet Explorer, try to access this webpage using Google Chrome.

Gradient #2: From red (255,0,0) to blue (0,0,255) to red (255,0,0)


color-gradient-2

This code is slightly different as we want the red code to decrement from 255 to 0 while the blue code increments from 0 to 255. Check how it’s done in the code below:

Gradient #3: From cyan (0,255,255) to magenta (255,0,255) to cyan (0,255,255)


color-gradient-3

Tweak the code in one of the trinkets above to implement this gradient.

Gradient #4: From cyan (0,255,255) to yellow (255,255,0) to cyan (0,255,255)


color-gradient-4

Tweak the code in one of the trinkets above to implement this gradient.

Gradient #5: From green (0,255,0) to yellow (255,255,0) to magenta (255,0,255) to cyan (0,255,255) to green (0,255,0)


color-gradient-5

Tweak the code in one of the trinkets above to implement this gradient.

Gradient #6: From black (0,0,0) to white (255,255,255) to black (0,0,0)


color-gradient-6

Tweak the code in one of the trinkets above to implement this gradient.

unlock-access

Solution...

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

My Charts

chartFor this challenge we are going to use Python turtle to create some charts: Column charts, line charts and radar charts.

First we need a data set. We will use the following data that shows the market share of the four most popular browsers in 2015.

Web-browser Percentage
Chrome 44%
Safari 20%
IE / Edge 14%
Firefox 12%
Other 10%

Your Challenge


Using Python Turtle, create the following charts:
chart-column

chart-line

chart-radar

Python Turtle


Looking at the following code can you explain the purpose of each Python Turtle instructions:

  • myPen.color(“red”)
  • myPen.forward(100)
  • myPen.right(90)
  • myPen.left(45)
  • myPen.penup()
  • myPen.pendown()
  • myPen.goto(0,0)
  • myPen.beginfill()
  • myPen.end_fill()
  • myPen.begin_fill()
  • myPen.write(“Hello World”, None, “center”, “16pt bold”)

(x,y) coordinates using Python Turtle?


quadrant-coordinatesOn this trinket widget the turtle screen is 400 pixels wide by 400 pixels high. So:

  • the top left corner coordinates are (-200,200)
  • the top right corner coordinates are (200,200)
  • the bottom left corner coordinates are (-200,-200)
  • the bottom right corner coordinates are (200,-200)
  • the centre of the screen coordinates are (0,0)



Look at the canvas below to understand how (x,y) coordinates work:

Challenge #1: Complete the code


We have started the code by creating a function called drawColumnChart(). This function takes five parameters – the values of the five columns to appear on the chart.

The code below shows you how to draw the first column. Your job consists of completing this code to draw all five columns.

Challenge #2: Line chart


Using a similar approach add a new function called drawLineChart() to draw a line chart using the same five values.
chart-line

Challenge #3: Radar chart


Using a similar approach add a new function called drawRadarChart() to draw a radar chart using the same five values.
chart-radar

Tagged with: ,

Penalty Shootout

soccerFor this challenge you are going to write a computer program where the user tries to score a goal against the computer.

The user will be asked where do they want to shoot and will have to choose one of the following five options:

  • TL: Top Left,
  • BL: Bottom Left,
  • M: Middle,
  • TR: Top Right,
  • BR: Bottom Right.

football-goal

The computer will act as the goal keeper and randomly choose one of these options too.

The program will decide if there is a goal or not by comparing the user’s choice with the computer option.

Complete the code


We have started the code for you. You need to complete it further:

Video Tutorial


Extension Task 1:


Create a second level where the computer can block up to two locations which are next to each other such as:

  • Bottom left and right left,
  • Bottom left and middle,
  • Top right and middle,
  • etc.

Extension Task 2:


Give the end-user a choice: do they want to shoot the penalty or be the goal keeper? Adapt your code to cater for both options.

Extension Task 3:


Create a program where the computer and the player take it in turn. The program adds up the scores and stops on a best of 5 scores. (e.g. 3-0, 4-1, 4-2, 5-3, 5-4)
unlock-access

Solution...

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

Binary Logic Activities

Access a range of activities about binary logic, logic gates, truth tables and Karnaugh maps:
Binary Activities for GCSE Students Binary Activities for A Level Students

binary-logic-screenshots

Tagged with: , , ,

BBC micro:bit – Project Ideas

On this blog post we are listing a few projects that could be implemented using a BBC micro:bit using either the Block programming interface or the Python interface:

limit33

lottery-numbers

Morse_code

FizzBuzz

quoteOfTheDay

lightning-picture

7segments

number-plate-2

RockScissorsPaper

Karnaugh Maps

Karnaugh maps are a tool used to simplify complex Boolean expressions.

Using a Karnaugh map reduces the need for extensive calculations by taking advantage of humans’ pattern-recognition capability. Karnaugh maps are used to simplify real-world logic requirements so that they can be implemented using a minimum number of physical logic gates.

The picture below shows some of the different patterns that can be identified in a Karnaugh map using four inputs:

karnaugh-map-pattens

Here is another Karnaugh Map:

karnaugh-map

Try our on-line Karnaugh Map GeneratorCreate and share your own Karnaugh Maps
Tagged with: ,

Hexadecimal Colour Codes

Colour Palette

Colour PaletteLook at the picture on the right. Can you give a unique name to each of the colours displayed on the picture? (e.g. Lemon yellow, sunset yellow, tangerine etc.)

Do you know your colour codes? When building websites or Graphical User Interfaces (GUI) for your computer programs you will have to choose the colours you want to use.

In computing we can identify a colour using a unique colour code which consists of a # followed by 6 digits. This is called the hexadecimal RGB colour code. RGB stands for Red, Green and Blue. These 3 colours are in computing the the primary colours: which means that every colour is made of a combination of these three colours.

For instance, magenta (shade of purple) is made of a lot of red and a lot of blue and no green at all. Its colour code is #FF00FF, which is the hexadecimal equivalent of (255, 0, 255). It’s a bit like mixing paint: each colour is made of a bit of red paint (from 0 to 255), a bit of blue paint (from 0 to 255) and a bit of green paint (from 0 to 255). We can then convert these three numbers to hexadecimal.

Using this approach we can uniquely identify 255 x 255 x 255 = 16 million different shades of colours.

When choosing your colors you can use a site like colorpicker.com.

Check the following RGB Color picker to see how RGB codes work (Works best using IE):

Match the Colour Codes:



Complete this drag and drop activity to match the colours with their hexadecimal colour codes.

#C40000
#000000
#00FFFF
#00FF00
#750075
#AAAAAA
#FFFF00
#333333
#9999FF
#FFFFFF


WhiteDark Red
Light GreyLight Blue
Dark GreyYellow
BlackCyan
GreenPurple

Tagged with: