More results...

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

Currency Converter

currenciesOur aim is to create a currency converter to help us convert a sum of money from one currency to another.

Currency exchange rates are constantly changing which is why we have decided against the idea of storing all the exchanges rates in our code are these would not remain up-to-date. Instead we will retrieve up-to-date currency exchange rates by making calls to an API that provides the current rates.

To do so we will use the “Currency Converter API” to retrieve up-to-date exchange rates. You can read more about this API on: https://currencyconverterapi.com/. For the purpose of this blog post we will use the free version of this API.

This API works as follows:

API Request: e.g. Converting from US Dollars (USD) to British Pounds (GBP)

https://free.currencyconverterapi.com/api/v7/convert?q=USD_GBP&compact=y

JSON Output

{"USD_GBP":{"val":0.786905}}

This API uses JSON to format the data. JSON (JavaScript Object Notation) is a popular lightweight data-interchange format. Its main benefit is that it is easy for humans to read and write and it is easy for machines to parse and generate as you can see in the code provided below. You can read more about JSON on https://www.json.org/

Python Code


Check our code to see how we make a call to the API and how we retrieve and extract the requested JSON data.

Before running the code below, you will need to
request a free API key from currencyconvertapi.com
and insert this key on line 5 of the code below. Make sure you also follow instructions on how to verify your email to complete the API key request.

Your Task


Update the code above to accept a full range of currencies. You will need to use the API to retrieve a full list of currencies by making a request using the following URL: https://free.currencyconverterapi.com/api/v6/currencies

You will have to parse this JSON data to retrieve all the currency codes and append these to the list called validCurrencies currently declared on line 5 of the above trinket.

You may also want to output all the currency codes and the name of each currency to inform the user of the available codes and their meaning.

unlock-access

Solution...

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

Real-Time ISS Tracker

international-space-station
The International Space Station (ISS) is moving at close to 28,000 km/h and orbits the Earth 16 times per day, once every 90 minutes! In this python challenge we are going to use an open source API (Open Notify) to retrieve some real-time data from Nasa about the location of the ISS.

Our aim is to retrieve the current longitude and latitude of the International Space Station and to use this information to plot it on the map.

You can read more about the API on: http://open-notify.org/Open-Notify-API/ISS-Location-Now/

Note that we will also use the Open Notify API to retrieve the current numbers of astronauts in space and to retrieve all their names and the spacecraft they are on. You can read more about this API on: http://open-notify.org/Open-Notify-API/People-In-Space/

Both these APIs use JSON to format the data. JSON (JavaScript Object Notation) is a popular lightweight data-interchange format. Its main benefit is that it is easy for humans to read and write and it is easy for machines to parse and generate as you can see in the code provided below. You can read more about JSON on https://www.json.org/

Python Code


Check our code to see how we make a call to the API and how we retrieve and extract the requested JSON data. You may need to see this trinket in full screen view to see the position of the ISS on the world map. An infinite “while True” loop is used to constantly update the position of the ISS on the map, with a 5-second delay between each iteration.

Your Task


The Open Notify API provides a third API to find out when the ISS will next pass over a specific location. The API requires you to provide the longitude and latitude of a location and returns a list of the next 5 date and time timestamps when the ISS will pass over, or closed to, this location.

You can find out more about this API on http://open-notify.org/Open-Notify-API/ISS-Pass-Times/

Your task is to write a Python script to display the date and time of the next five passes of the ISS over Paris, France (longitude: 45.51° N, latitude: 2.20° E).

Note that you will need to use the time library to convert a Unix Epoch Timestamp into a human readable format, using the following code:

import time
timestamp = 1547281745
datetime = time.strftime('%A, %Y-%m-%d %H:%M:%S', time.localtime(timestamp))
print(datetime)
unlock-access

Solution...

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

3D Snowman

In this blog post we will use Glowscript to create a 3D animation of a snowman.

Our aim is to create our snowman by adding different 3D shapes such as spheres, cylinders, cones, etc. We will then create a compound object to join these shapes together in a single object. Finally, we will use an infinite while loop to animate/rotate the snowman around the Y axis.

Glowscript/vPython?…


To complete this challenge and find out about all the 3D shapes you can use in Glowscript, you will need to refer to the Glowscript/vPython online documentation.

(x,y,z) Coordinates


Note that to complete this challenge you will need a good understanding of how 3D coordinates work:
xyz-axis

snowman-coordinates

Complete the code


We have started the code for you. Your task is to complete this code to customise this snowman further. (Use Google Chrome to preview this animation)

Right Click on the animation to change the view point (rotate camera angle).

Extension Task


snow-globeBuild a snow globe around your snowman. You will need to use an opacity argument when creating the glass sphere.

unlock-access

Solution...

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

Target Detection Algorithm

targeting-computer-algorithmIn star wars movies, most spaceships are fitted with laser cannons to shoot enemy spaceships. To assist the pilot, these spaceships have built-in targeting computers that enable them to aim the cannon and inform them when their target is within reach. When this is the case, the algorithm informs the pilot with the following message:

target-acquired

We have retrieved the code used in a Star Wars Tie Fighter spaceship. The code is used to aim the laser cannon. However this spaceship is not fitted with a target acquisition algorithm to inform the pilot when to shoot.

star-wars-spaceship

Your aim is to upgrade this code to detect when the enemy spaceship is within reach of the laser cannon.

To do so you will need to check if the X, Y coordinates of the cannon aim (mouse pointer) is within the A B C triangle representing the enemy spaceship:
target-acquired-coordinates

Python Code


Your aim is to upgrade this code from line 60 to detect when the enemy spaceship is within reach of the laser cannon:


unlock-access

Solution...

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

Periodic Table of Programming Concepts

This periodic table of programming concepts list the main concepts and techniques used in procedural programming. High level procedural programming languages such as Python, Visual Basic, C, etc. enable you to use most, if not all of these concepts in your code.

Click on the concepts below to reveal short definitions of each concept.

Programming Concepts – Periodic TableOpen in new tab/window

My Javascript Calculator

For this challenge, you will use your HTML, CSS and JavaScript to create a fully functional calculator as follows:
js-calculator

Before attemtping this challenge, make sure you gain a full understanding of how HTML, CSS and JavaScript are used on a web page and how these three client-side languages interact with each other by completing the following challenges:

HTML, CSS & JS Code


We have started the code for you. Click on the “Edit on Codepen” button to edit this code and implement your calculator.

See the Pen JS: Add String (with parseInt) by 101 Computing (@101Computing) on CodePen.

A Puzzling Algorithm

a-puzzling-algorithm
This algorithm is based on:
sequencing-label

Test Plan


To understand what this algorithm is meant to do, we will predict its expected output for different input values and record our predicted outputs in a test plan.

Test # Input Values Expected Output
#1 a = 7
b = 2
#1 a = 3
b = 9
#1 a = 150
b = 10

Now that you have completed the “expected output” column of this test plan you might be able to explain what this algorithm actually does?

You can now use our online Python IDE to implement this algorithm and complete each test from the above test plan.

unlock-access

Solution...

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

Understanding Bitmap Pictures

resolution-and-colour-depthIn this blog post we are investigating what are bitmap pictures and how they are stored on a computer using binary code.

Bitmap Pictures?


Bitmap pictures (also called raster graphics) are computer graphics made of pixels of different colours. Pictures taken with a digital camera (or a scanner) are bitmap pictures. It is also possible to create bitmap pictures using software such as Paint, Photoshop or the Gimp.

.bmp, .tif, .png, .gif and .jpg are all file extensions for different types of bitmap pictures.

Bitmap Picture Quality


The qualify of a bitmap picture relies on mainly two criteria:

  • The resolution of the picture,
  • The colour depth of the picture.

Resolution


The quality of a picture is directly linked to the number of pixels in the picture. The number of pixels in a picture depends on the width, height and resolution of a picture.

  • The width and height of a picture can be given in pixels or inches.
  • The resolution of a picture is the number of pixels per inch and is measured in dpi (dots per inch) or ppi (pixels per inch).

A higher resolution picture contains a higher number of pixels which results in better quality but also a larger file size.

A higher resolution results in better quality pictures.

A higher resolution results in better quality pictures.

A typical resolution for a picture used on a website would be 72 ppi.
For printing purposes, high quality printing would require a higher resolution (e.g 200 ppi, 300 ppi or even 600 ppi).

A higher resolution picture can be enlarged (zoom in) and may still remain crisp whereas a lower resolution picture will look pixelated when enlarged. So when taking pictures with a smartphone or a digital camera, it is important to consider what will the picture be used for. If the intention is to print large canvas of a picture, it will need to be saved using the highest resolution settings, even though it will take more storage space on the device.

color-depth

Colour Depth


The Colour depth (or color depth – american spelling) of a picture corresponds to the number of bits used to represent the colour value of a single pixel.

Let’s look at the following pixel art widgets below. They are all based on a different colour depths varying from 1 bit per pixel to 4 bits per pixel.

Colour Depth: 1 bit per pixel2 bits per pixel3 bits per pixel4 bits per pixel

A you can see a pictue with a higher colour depth uses a higher number of bits per pixel which results in a wider range of colours hence better quality but also a larger file size.

Most bitmap graphics you would find on the web (especially .png or .jpg) would use a colour depth of 24 bits, resulting in a colour palette of 224 (more than 16,000,000) colours.

The RGB colour coding system uses such a colour depth using 3 Bytes = 24 bits per pixel.

Let’s recap…


Complete this drag and drop activity to highlight the key concepts of bitmap graphics.

dpi
pixels
depth
quality
colours
raster
bits
file size
resolution
pixelate
higher
inch

Bitmap pictures, resolution & colour depth

  • Bitmap pictures are also known as graphics and are made of of different colours.
  • The two main factors which affect the quality of a bitmap picture are and colour depth.
  • The resolution is the number of pixels per , measured in dots per inch () or pixels per inch (ppi).
  • The higher the resolution the better the of the picture. A picture with a low resolution will when the picture is enlarged.
  • The colour is the number of per pixel.
  • The the colour depth, the wider the range of available, hence the higher the quality of the picture, and the larger the .

The Pizzaiolo’s Puzzle

PIZZAA pizzaiolo (a man who makes pizza) has been asked to produce a very large pizza, to sprinkle some Parmesan cheese evenly on the pizza and to spread a full jar of black olives (approximately 80 olives) on the pizza.

He has decided to find a method to evenly spread the olives on the pizza to ensure that:

  • the olives cover the entire pizza,
  • the olives are relatively equidistant from each others,

Fermat’s Spiral & Vogel’s Model


After doing some research online, our pizzaiolo came across the following webpage about Fermat’s Spiral, and was captivated to find out about how the Vogel’s model could be used to calculate the polar coordinates of each olive to be added to his pizza:

Vogel's Model

  • Where θ is the angle,
  • r is the radius or distance from the centre,
  • n is the index number of the olive,
  • c is a constant scaling factor,
  • The angle 137.508° is the golden angle which is approximated by ratios of Fibonacci numbers.

Python Code


The following Python Turtle demonstrates how Vogel’s model can be used to solve our pizzaiolo’s puzzle:

Your Task


Update the code above to add extra ingredients to your pizza (e.g. pepperoni slices). Try different values instead of the golden angle to see the impact on the resulting pattern.
pizzas
unlock-access

Solution...

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

The Box Swap Puzzle

How many steps would it take to move the chicken into box b and the elephant into box a, knowing that you cannot have more than one animal per box?

box-swap-puzzle
View Solution
box-swap-solution

Using variables


In a computer program, variables are used to hold values that the program will be abe to access and change if necessary. Variables can contain different types of values such as strings (e.g. “Hello World”), numbers (integers or reals) or Boolean (True or False) values.

Each variable is given a meaningful identifier, chosen by the programmer such as message, playerName, score, numberOfLives.

The assignment operator = is used to assign/store a value to a variable.

e.g.

message = "Hello world!"
playerName = input("Enter your name")
score = 0
numberOfLives = 3

The Swapping Puzzle


Let’s replace the cardboard boxes from the above box swap puzzle with three variables called a, b and temp. We can initialise our variables a and b with their initial values as follows:

a = "chicken"
b = "elephant"

We can solve the above puzzle to swap the content of our two variables using the same three-step approach as follows:
box-swap-using-variables

a = "chicken"
b = "elephant"

temp = a
a = b
b = temp

print("Variable a = " + a)
print("Variable b = " + b)

Your Challenge


Write a program that asks the user to enter two values between 1 and 10 and assign these values to two variables called number1 and number2.

Add some code to ensure that number1 ends up with the highest of the two values and number2 with the lowest of the two values. In other words, if number1 is smaller than number2, swap the content of the variables number1 and number2.

Output number1 and number2 on screen.

To complete this challenge, you will have to complete the Python code below:

Extension Task


Extend your code to retrieve three user inputs and swap these to display them in ascending order.

podium

unlock-access

Solution...

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