More results...

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

Taboo Revision Game (A Level)

taboo-cardsCheck our version of the Taboo game focusing on A level computer science terminology. The objective of the game is for a player to have their partners guess the word on the player’s card without using the word itself or five additional words listed on the card. The player has a fixed amount of time (30 seconds, one minute or two minutes, to be agreed at the start of the game). They should use this time to get their partners to guess as many words as possible.

If the player passes a card or uses one of the taboo words, they lose one point. For every word that is correctly guessed by their partners, they score one point. The player is not allowed to use any forms of the word listed. When acronyms are used, the player is not allowed to use any of the words that the acronym stands for.

One the cards below, the words to be guessed appear at the top of the card (white font) whereas the taboo words are listed on the white section of the card (grey font).
A Level Computer Science RevisionOpen Taboo Game in New Window

The commuter’s puzzle

to-the-moon-and-backYuri lives in Oxford, UK and commutes by train to his work place in London every working day of the week (5 days a week).

One evening, Yuri spot the Moon through the train window and asked himself the following question:

“In how many years will I have travelled the equivalent distance of going to the Moon and back due to my daily commute?”

On a piece of paper Yuri has gathered some data needed to answer this question:

Description Value
Distance between Oxford and London: 60 miles
Distance between planet Earth and the Moon: 383,400km
Number of km in 1 mile: 1.609km
Number of working days per week: 5
Number of weeks in a year: 52

He has also drawn the following flowchart to help him find the answer. His intention was to then use some Python code to implement this flowchart and work out the answer to his question. This algorithm is a sequencing algorithm based on the following steps:

  1. Work out the total distance travelled over a year (in km).
  2. Work out the distance of a return journey to the Moon (in km).
  3. The number of years can be calculated by dividing the distance of a return journey to the Moon by the total distance travelled over a year.

sequencing-label
flowchart-to-the-moon-and-back

Python Code


You can use the above flowchart to complete the Python code for this sequencing algorithm.

unlock-access

Solution...

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

Mission Alpha-Centauri

Did you know that Alpha-Centauri is the second nearest star to planet Earth, the first one being the Sun. It is 4.2 light-years away from us!

When astronomers measure the distance of stars (from planet Earth) they do not use the kilometer (km) unit but instead they use the light-year unit. One light-year represents the distance that light travels in one year, at the speed of light (300,000 km/s).

stars-galaxy
The aim of this challenge is to convert the distance between planet Earth and Alpha-Centauri from light-years to km.

To do so we will use a sequencing algorithm based on the following steps:

  1. Calculate the number of seconds in a year,
  2. Multiply this number by the speed of light,
  3. Multiply this number by 4.2 (the distance of Alpha-Centauri from Earth in light-years).
  4. Output the result/ distance in km

sequencing-label

Flowchart


The flowchart of this sequencing algorithm is as follows:
alpha-centauri-flowchart

Python Code


You can now implement this sequencing algorithm using Python code:

Step 2: using Selection


Your next challenge is to let the user choose a star, and based on their choice, you will output the distance between the selected star and planet Earth, in km using the following data:

Star Distance from Earth (in light-years)
Alpha Centauri 4.24 light-years
Barnard’s Star 5.96 light-years
Luhman 16 6.59 light-years
WISE 0855-0714 7.2 light-years
Wolf 359 7.78 light-years

To do so you will use an if, elif and else statements to implement a selection construct.
selection-label

Step 3: using Iteration


Finally, using a while loop, you will keep asking the user to choose a star to repeat the above process with the user’s selection, until the user decides to quit the program. Using a while loop is an example of iteration!
iteration-label

Tagged with: , ,

2D Rotation Matrix

In this post, we will investigate how we can use the 2D rotation matrix to calculate the coordinates of a point when applying a 2D rotation of a set angle, Θ.
2D-Rotation

Here is the 2D rotation matrix:
2D-Rotation-Matrix

Which results in the following two equations where (x,y) are the cartesian coordinates of a point before applying the rotation, (x’,y’) are the cartesian coordinates of this point after applying the rotation and Θ is the angle of rotation
2D-Rotation-Coordinates

2D Rotation Demo


We have created a demo using the processing library to represent an X-Wing spacecraft (top-down view). The spacecraft is defined as a list of shapes, where each shape is a sublist of (x,y) coordinates (the vertices of the polygonal shape).

We are then applying the 2D rotation formulas to apply an angle of rotation (calculated based on the position of the mouse cursor on the canvas) and hence calculated the new coordinates of each vertices.

Finally, using the line() function of the processing library we the draw the spacecraft by plotting and joining all these vertices together.

Python Typing Text Effect

keyboard-typingIn this blog post we will revisit two of the key python functions: print() and input() in order to improve the user experience of our Python programs.

As you know, the print() function in Python is used to output a message on screen, whereas the input() instruction displays a message/question on screen and retrieves a user input that the user will type using their keyboard.

Our aim is to improve the display of text on the screen by adding a typing effect/delay.

To do so we will need to import two libraries: time and sys. We will then create two new functions called typingPrint() and typingInput() as follows:

import time,sys

def typingPrint(text):
  for character in text:
    sys.stdout.write(character)
    sys.stdout.flush()
    time.sleep(0.05)
  
def typingInput(text):
  for character in text:
    sys.stdout.write(character)
    sys.stdout.flush()
    time.sleep(0.05)
  value = input()  
  return value

We will then be able to use these two functions in our program instead of the usual print() and input() functions.

Finally, to improve the user experience further, we have also created a clearScreen() function which relies on importing the os library. This function can be used at anytime to clear the screen from previous outputs and inputs. It’s ideal when creating menu based systems, splash screes, quiz based games, two player games and so on… Here is the code for our clearScreen() subroutine.

import os
 
def clearScreen():
  os.system("clear")

Demonstration


Let’s see how to use our functions in small text-based program:

Tagged with:

What if planet Earth was made of Lego?

In this blog post we will use a Python script to work out how many lego bricks would be needed to build planet Earth!

To solve our problem we will use the following data:
planet-Earth-lego-brick

We will work out the number of lego bricks needed in several step using a sequencing algorithm: An algorithm consisting of instructions that are carried out (performed) one after another.
sequencing-label
We will use the following steps:

  1. Convert all measurement to the same unit (e.g. mm)
  2. Calculate the volume of planet Earth
  3. Calculate the volume of a lego brick
  4. Number of bricks needed = volume of planet Earth / volume of a lego brick

We will need to use the following two formulas:
volume-sphere-cuboid

The complete flowhchart for our algorithm:
what-if-planet-earth-was-made-of-lego-flowchart

Python Code


You can now code this algorithm using Python to reveal the answer to the initial question: how many lego bricks are needed to build planet Earth!

Number of lego bricks


If you have completed this algorithm, the final answer should be approximatively:
≈ 4.23 x 1026 (in standard form)

≈ 423,000,000,000,000,000,000,000,000 lego bricks!

Using subroutines


It is good practice to use subroutines whenever possible as these can then easily be reused in other programs. Your task is to adapt your code by defining a d using two functions as follows:

  1. Your first subroutine should be called getVolumeOfSphere(), take one parameter called radius and apply the relevant formula to calculate and return the volume of a sphere based on the given radius.
  2. Your second subroutine should be called getVolumeOfCuboid(), take three parameters called width, length and height and apply the relevant formula to calculate and return the volume of a cuboid based on the given dimensions.
unlock-access

Solution...

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

Lemon Drizzle Cake Recipe (HTML Task)

lemon-drizzle-cakeIn this blog post we are going to help Elian save his favourite cake recipe as a web page. Elian has already typed all the instructions for his lemon drizzle cake recipe but needs your help to format how the text appears on the page. To help him improve the look and feel of his page you will need to complete the six tasks listed below.

But first let’s look at Elian’s HTML page so far:

See the Pen
Lemon Drizzle Cake Recipe
by 101 Computing (@101Computing)
on CodePen.


To edit Elian’s code, you will need to click on the “Edit on codepen” button in the top right corner above.

Your Tasks


Task 1: HeadingsTask 2: Bullet pointsTask 3: ColoursTask 4: Formatting textTask 5: HyperlinksTask 6: Your turn

Task 1: Headings and Paragraphs


In order to give this page more structure we are going to add some headings, subheadings and paragraphs. We will do so using the following HTML tags:

<h1>Heading 1</h1>

<h2>Heading 2</h2>

<h3>Heading 3</h3>

<h4>Heading 4</h4>

<h5>Heading 5</h5>
<h6>Heading 6</h6>


<P>Paragraph</P>


Your task is to update Elian’s code by adding some <h1> tags for the main heading:

  • Lemon Drizzle Cake Recipe

And some <h2> tags for the subheading of the page:

  • About the Recipe:
  • Ingredients:
  • Recipe for the cake:
  • Recipe for the lemon drizzle:
  • Finding more recipes online:

All other pieces of text should be displayed as paragraphs using <p> tags.

Note that, within a paragraph, we can also force the text to go to the next line using the <br/> tag.
Watch Video Tutorial #1

Bullet Points Lists


In HTML, you can create a list of bullet points using both <ul> tags and <li> tags as follows.

<ul>
   <li>First Bullet point!</li>
   <li>Second Bullet point!</li>
   <li>Third Bullet point!</li>
</ul>

Your task consist of displaying all the ingredients using bullet points so that it appears on the web page as follows:

  • 225g unsalted butter
  • 180g caster sugar
  • 4 eggs
  • 225g self-raising flour
  • 1 lemon, zested
  • 2 lemons, juiced
  • 65g caster sugar

You can also use a similar approach to create a numbered list as opposed to a bullet point list. To do so, use an <ol> tag instead of the <ul> tag. You can for instance display the steps of the recipe using a numbered list:

  1. Pre-heat the oven to 180°C.
  2. Beat together the butter and caster sugar until creamy, then add the eggs, one at a time, slowly mixing through.
  3. Sift in the self-raising flour, then add the lemon zest and mix until well combined.
  4. Line a loaf tin (8 x 21cm) with greaseproof paper, then pour in the mixture and level the top with a spoon.
  5. Bake for 45 to 50 minutes.
Watch Video Tutorial #2

Adding Colours!


We are now going to change the text colour using the <font> tag.

For instance to make text appear in orange we can use the following code:

<font color="orange">This text will appear in orange!</font>

Notice the American spelling for the attribute “color” inside the font tag!

Your task is to use several <font> tags to make the information such as preparation time, cooking time, level of difficulty and number of servings standout on the page using the colours of your choice.
Watch Video Tutorial #3

Centred ,Bold, Italic and Underlined Text


You can use the <center>, <b>, <i> and <u> tags to make text appear in the centre, in bold, in italic or underlined.

<center>This text will appear in the centre!</center>
<b>This text will appear in bold!</b>
<i>This text will appear in italic!</i>
<u>This text will appear underlined!</u>

Adapt Elian’s code so that some of the key information from the recipe appear in bold or in italic.
Watch Video Tutorial #4

Adding hyperlinks


To add a hyperlink, you will need to use the <a> tag as follows:

<a href="https://www.101computing.net">Visit our computing blog!</a>

You can now add a hyperlink to the last paragraph to point to the BBC Good Food website. The URL of the page is: https://www.bbcgoodfood.com/
Watch Video Tutorial #5

Your Turn


Now that you know how to use the basic HTML tags needed to create a web page, add some more content to this webpage:

  • Add a section called “Tip of the day” (as a Heading 2). Add a paragraph to this section with the following text:
  • “To find out is your cake can come out of the oven, insert a thin skewer or knife into the centre of the cake. Your skewer/knife should come out clean. If it doesn’t you will need to leave the cake to bake for a bit longer.”

  • Find some other recipes online and create hyperlinks to these pages.
unlock-access

Solution...

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

The colours of the rainbow (HTML task)

rainbowIn this blog post we are going to help Asya complete her homework research task about rainbows. Asya has collated a range of interesting facts about rainbows and has decided to submit her work as an HTML page.

She has started her page but needs your help to format this page further using a range of HTML tags. To help her improve the look and feel of her page you will need to complete the six tasks listed below.

But first let’s look at Asya’s HTML page so far:

See the Pen
Rainbow Facts
by 101 Computing (@101Computing)
on CodePen.


To edit Asya’s code, you will need to click on the “Edit on codepen” button in the top right corner above.

Your Tasks


Task 1: HeadingsTask 2: Bullet pointsTask 3: ColoursTask 4: Formatting textTask 5: HyperlinksTask 6: Your turn

Task 1: Headings and Paragraphs


When creating an HTML, page it is good practice to include headings, eventually subheadings and paragraphs. We can do so using the following HTML tags:

<h1>Heading 1</h1>

<h2>Heading 2</h2>

<h3>Heading 3</h3>

<h4>Heading 4</h4>

<h5>Heading 5</h5>
<h6>Heading 6</h6>


<P>Paragraph</P>


Your task is to update Asya’s code by adding some <h1> tags for the main heading:

  • Rainbow facts!

And some <h2> tags for the subheading of the page:

  • Colours of the rainbow
  • What Makes a Rainbow?
  • Rainbow Myths
  • Find out more:

All other pieces of text should be displayed as paragraphs using <p> tags.
Watch Video Tutorial #1

Bullet Points Lists


In HTML, you can create a list of bullet points using both <ul> tags and <li> tags as follows.

<ul>
   <li>First Bullet point!</li>
   <li>Second Bullet point!</li>
   <li>Third Bullet point!</li>
</ul>

Your task consist of displaying the seven colours of the rainbow using bullet points so that it appears on the web page as follows:

  • Red,
  • Orange,
  • Yellow,
  • Green,
  • Blue,
  • Indigo,
  • Violet.
Watch Video Tutorial #2

Adding Colours!


We are now going to change the text colour using the <font> tag.

For instance to make text appear in red we can use the following code:

<font color="red">This text will appear in red!</font>

Notice the American spelling for the attribute “color” inside the font tag!

Your task is to use several <font> tags to display each colour of the rainbow in its own colour.
Watch Video Tutorial #3

Centred ,Bold, Italic and Underlined Text


You can use the <center>, <b>, <i> and <u> tags to make text appear in the centre, in bold, in italic or underlined.

<center>This text will appear in the centre!</center>
<b>This text will appear in bold!</b>
<i>This text will appear in italic!</i>
<u>This text will appear underlined!</u>

Adapt Asya’s code so that the myth “There’s a pot of gold at the rainbow’s end.” appears in the centre of the page, in bold, and in italic.
Watch Video Tutorial #4

Adding hyperlinks


To add a hyperlink, you will need to use the <a> tag as follows:

<a href="https://www.101computing.net">Visit our computing blog!</a>

You can now add a hyperlink to the last paragraph to point to the wikipedia page about rainbows. The URL of the page is: https://en.wikipedia.org/wiki/Rainbow
Watch Video Tutorial #5

Your Turn


Now that you know how to use the basic HTML tags needed to create a web page, add some more content to this webpage:

  • Find some cool facts about rainbows and add them to the existing sections or create a new sub-heading to add your new content.
  • Find some other webpages about rainbows and create hyperlinks to these pages.
unlock-access

Solution...

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

Standard Form Conversion Algorithm

standard-formStandard form (a.k.a. standard index form), is a system of writing numbers which is particularly useful when using either very large or very small numbers. It is based on using powers of 10 to express how big or small a number is.

Standard form is written in the form of a x 10n, where is a number between 1 and 10 (bigger than or equal to 1 but strictly lower than 10). For large numbers, n is a positive whole number, whereas for small numbers, n is negative whole number.

stars-galaxy

The standard form is for instance used by astronomers as the distance between stars is very high, resulting in numbers which are not easy to write down and memorise without using the standard form. For instance did you know that Alpha Centauri was the second nearest planet (after the Sun) to planet Earth. It is located 4.37 light-years away from the Sun. Considering that a light-year is the distance travelled by light in one year and knowing that light travels at 300,000 km per second we can work out the distance in km between Alpha Centauri and the Sun as follows:

4.37 light-years = 4.37 x 365.25 x 24 x 60 x 60 x 300,000 ≈ 41,400,000,000,000 km

In standard form:
4.14 x 1013 km

h2o-moleculeSimilarly, physicists and chemists use the standard form when using very small numbers. For instance, the size of a molecule of water (H2O) is about 0.27 of a nanometer.

0.27 nanometers = 0.00000000027 meters

In standard form:
2.7 x 10-10 meters

Programming Challenge


Our aim is to write a procedure that takes a number as a parameter and outputs this number in standard form. To do so, our procedure will be based on the following algorithm:
standard-form-conversion-flowchart

Python Code


Complete the python code using the trinket below:

Test Plan


All done? It’s now time to test your code to see if it works as expected.

Test # Input Values Description Expected Output Actual Output
#1 41400000000000 The distance (in km) between the Sun and Alpha Centauri 4.14 x 1013
#2 0.00000000027 The size (in meters!) of a molecule of water. 2.7 x 10-10
#3 5972000000000000000000000 The mass (in kg) of planet Earth 5.972 × 1024
#4 1898000000000000000000000000 The mass (in kg) of Jupiter 1.898 × 1027
unlock-access

Solution...

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

Find the Logic Error

Check the following pieces of code. The syntax of the code is correct and the programs do run. However, while testing these programs, you will notice that they do not always produce the expected output! This is because each program contains a logic error. Can you spot and fix these logic errors?

Program 1:Program 2:Program 3:Program 4:Program 5:Program 6:

Higher or Lower?


The aim of this program is to identify the highest number from 2 user inputs:

Test Plan:

Test # Input Values Expected Output Actual Output
#1 a: 3
b: 4
4
#2 a: 5
b: 2
5
#3 a: 6
b: 6
6
#4 a: 12
b: 4
12

Average Score?


The aim of this program is to calculate the average score out of 3 scores:

Test Plan:

Test # Input Values Expected Output Actual Output
#1 Score #1: 10
Score #2: 20
Score #3: 30
20
#2 Score #1: 0
Score #2: 0
Score #3: 30
10
#3 Score #1: 50
Score #2: 50
Score #3: 50
50
#4 Score #1: 20
Score #2: 70
Score #3: 30
40

Your age in the future?


The aim of this program is to calculate how old you will be in a given number of years:

Test Plan:

Test # Input Values Expected Output Actual Output
#1 Age: 15
Gap: 5
Age: 20
#2 Age: 18
Gap: 30
Age: 48
#3 Age: 20
Gap: 80
Age: 100

What’s my grade?


The aim of this program is for the user to input a test score and for the program to output a grade as follows:

  • Any score below 50 should receive a U grade
  • Any score between 50 and 69 should receive a Pass grade
  • Any score between 70 and 89 should receive a Merit grade
  • Any score of 90 or above should receive a Distinction grade


Test Plan:

Test # Input Values Expected Output Actual Output
#1 Score: 30 Grade: U
#2 Score: 65 Grade: Pass
#3 Score: 82 Grade: Merit
#4 Score: 97 Grade: Distinction
#5 Score: 102 Invalid Score!
#6 Score: 0 Grade: U
#7 Score: 50 Grade: Pass
#8 Score: 69 Grade: Pass
#9 Score: 70 Grade: Merit
#10 Score: 89 Grade: Merit
#11 Score: 90 Grade: Distinction
#12 Score: 100 Grade: Distinction

Tip of the day!


The aim of this program is to generate a tip of the day based on the weather conditions.

Test Plan:

Test # Input Values Expected Output Actual Output
#1 Sunny: Yes
Rainy: Yes
Snowy: No
Windy: Yes
You might see a rainbow today!
Wear a raincoat!
Have a good day!
#2 Sunny: No
Rainy: Yes
Snowy: No
Windy: No
Take your umbrella!
Have a good day!
#3 Sunny: No
Rainy: No
Snowy: Yes
Windy: Yes
Wear a raincoat!
Have a good day!

Factorial!


The aim of this program is to calculate the factorial of any given number. e.g. 5! = 5x4x3x2x1 = 120

Test Plan:

Test # Input Values Expected Output Actual Output
#1 5 5! = 120
#2 10 10! = 3628800
#3 0 0! = 1