More results...

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

Flags of the World

We are trying to build a program that will ask the end-user to choose a flag amongst six flags. The program will then try to guess the selected flag by asking a maximum of two questions.

Look at the flowchart below used to describe our algorithm: (Click on flowchart to open in new window)
flags of the world flowchart

Challenge #1


Analysing this flowchart, can you guess the country corresponding to these six flags? (Type your answer below each flag).

Flag-Tanzania Flag-Turkey Flag-Luxembourg
Flag-Ghana Flag-Sweden Flag-Chad

Challenge #2

Using Flowchart Studio, design a similar flowchart used for the computer the guess the correct flag amonst these six new flags. You will need to ask different questions.

Flag-Jamaica Flag-China Flag-Iceland
Flag-Colombia Flag-Cuba Flag-Denmark

Challenge #3


Can you tweak the algorithm from the previous task to get the computer to guess the correct flag amongst all twelve flags, using a maximum of three consecutive questions?

Tagged with: ,

Fireworks Display

fireworks

Coding is an Art


Let’s first whatch this video clip which shows how a computer program can be used to create a large scale, live and interactive fireworks display:
Watch video clip

Fireworks Code


Inspired by this application of computer science, we have decide to create our own firework display using a Python script.

For this challenge we are using the processing library which is used to draw on the screen and to refresh the screen based on a frame rate. This is what we need to create our fireworks animation, based on a 24 frames per second.

Your task:


Analyse the code above. Change some of the parameters to see the impact on the aimation. Customise your fireworks further based on your preferences.

Interactive Fireworks


Let’s make an interactive fireworks display that responds to the user typing on the keyboard.
To test this script make sure you click on the fireworks display first (while it’s running). Then you will be able to interact with it by pressing any key on the keyboard:

Tagged with: , ,

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

Privacy Overview

This website will store some information about your preferences on your own computer inside a tiny file called a cookie. A cookie is a small piece of data that a website asks your browser to store on your computer or mobile device. The cookie allows the website to remember your actions or preferences over time.

You can delete all cookies that are already on your computer, and you can set most browsers to prevent them from being placed. However, if you do this, you may have to manually adjust some preferences every time you visit a site, and some services and functionalities may not work.

Most browsers support cookies, but you can set your browser to decline them and can delete them whenever you like. You can find instructions here for how you can do that on various browsers.

This website uses cookies to:

  1. Identify you as a returning user and to count your visits in traffic statistics analysis
  2. Remember your custom display preferences (such as light/dark theme option)
  3. Provide other usability features, including tracking whether you have already given your consent to cookies

Enabling cookies is not strictly necessary for the website to work but it will provide you with a better browsing experience.

The cookie-related information is not used to identify you personally and is not used for any purpose other than those described here.

There may also be other types of cookies created after you have visited this website. This site uses Google Analytics, a popular web analytics service that uses cookies to help to analyse how users use the site. The information generated by the cookie about your use of this website (including your IP address) will be transmitted to and stored by Google on servers in the United States. Google will use this information for the purpose of evaluating your use of other website, compiling reports on website activity, and providing other services relating to website activity and internet usage. Google may also transfer this information to third parties where required to do so by law, or where such third parties process the information on Google’s behalf. Google undertakes not to associate your IP address with any other data held by Google.