More results...

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

Circular Maze Challenge

The aim of this challenge is to use Python Turtle to trace a path to solve this circular maze.

By doing so we will investigate how we can draw different arcs of different radiuses and different lengths to guide the Python turtle through the maze.

Our Python code will make use of a function called drawArc() that takes three parameters:

  • The radius of the arc (in pixels)
  • The starting angle of the arc (in degrees)
  • The angle of the arc (in degrees)

To fully understand the purpose of these three parameters let’s look at the following three examples:

The third examples demonstrate how we can use a negative angle to change the direction of the arc. A positive angle draws an arc anti-clockwise, whereas a negative angle draws and arc clockwise.

Now let’s use Python Turtle to solve this challenge.

Python Code

We have started the code for you and drawn the first two arcs using our drawArc() function. Your task is to complete this code by drawing additional arc until you reach the exit gate.

To complete this challenge, you will have to use a trial and error approach, testing your code with different parameter values when using the drawArc(), forward() and setheading() functions and refining your code by tweaking these values.

unlock-access

Solution...

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

Pronic Numbers Challenge

A pronic number is a number which is the product of two consecutive integers.

For instance 42 is a pronic number because 42 = 6 x 7.

One approach to work out if a number n is a pronic number or not is to find out if there is a positive integer i lower than n that solve this equation: n = i(i+1).

If there is such a number i, then n is a pronic number.

Did you know?

Pronic numbers are also called oblong numbers or heteromecic numbers.

Python Challenge

Your task is to write new function called isPronic that takes one parameter, an integer value and returns True is the parameter is a pronic number, False otherwise.

You should then write a small program that will:

     Prompt the user to enter a number.
     Use the isPronic function to find out is the number entered is pronic or not.
     Produce a meaningful output to the end-user.

Extra Challenge

Reuse your function to write a new Python program that outputs all the pronic numbers between 0 and 1,000!

Python Code

unlock-access

Solution...

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

Olympics Host Cities (CSV Challenge)

For this challenge we are going to work with a list of host cities of the Olympic Games since the modern Olympics began in 1896. Our list will include both Summer and Winter games. This information is stored in a CSV file called olympics.csv. We will use a Python program to access this file and extract relevant data to answer specific queries about the Olympic Games.

Comma Separated Values (CSV)

Comma-separated values (CSV) is a text file format used to save tabular data. When considering a table of data, each line of the table is called a record. A record is made of fields. Each field stores a single value for each record.

To save this structured/tabular data, a CSV file uses commas (,) to separate values/fields, and newlines to separate records: each line of the file typically represents one data record. Each record consists of the same number of fields, and these are separated by commas in the CSV file.

Note that on occasions, it is not possible to use the comma as a separator if it is likely that the comma might be used in the data being stored. In this case a less common character might be used as a separator instead of the comma. This could be a semi-colon (;) or a pipe (¦). Even though the comma is not used, we can still consider such a file to be a CSV file.

In our case, our CSV file will use one line per Olympic Games. Each line/record will consists of four fieds:

year,city,country,season

You can see below the first few lines of the olympics.csv file:

1896,Athens,Greece,Summer,
1900,Paris,France,Summer,
1904,St. Louis,United States,Summer,
1908,London,United Kingdom,Summer,
1912,Stockholm,Sweden,Summer,
1920,Antwerp,Belgium,Summer,
1924,Chamonix,France,Winter,
1924,Paris,France,Summer,
...

Python Code

We can easily read the content of a text file in Python and iterate through each line of the file:

file = open("olympics.csv","r")
for line in file:
    print(line)      
file.close()

As each line consists of 4 fields separated by a comma, we can use the split() function in Python to convert each line into a list of values. We can then extract each value one at a time:

file = open("olympics.csv","r")
for line in file:
    data = line.split(",")
    year = data[0]
    city = data[1]
    country = data[2]
    season = data[3]    
    print(city + " hosted the " + season + " olympics in " + year)
file.close()

We have completed a Python script to scan through all the lines of the CSV file to only display a list of Summer Olympic Games and ignore the Winter games.

Your Task

Update the above code to let the user:

     List all the Winter Olympic Games
     List all the Olympic Games that were hosted in the United States
     Find out how many times did London (UK) host the Olympic Games
     Let the user enter a year and find out which city hosted the Olympic Games on the year they entered.
unlock-access

Solution...

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

Paris 2024 – JSON Challenge

The Paris 2024 Olympics provided a great opportunity for around 10,500 athletes to compete in 329 events, each event giving an opportunity for competing athletes to win one of the three medals: Gold, Silver and Bronze. All together, 206 countries were represented and the 2024 Olympics also included athletes from the IOC Refugee Team, which regroups displaced and refugee athletes.

For this programming challenge, we are going to search through a list of all the Paris 2024 medallists to answer specific queries and generate some statistics. All information about the Paris 2024 is stored in a JSON file called medals.json.

JavaScript Object Notation (JSON)

JavaScript Object Notation (JSON) is a lightweight, text-based format for storing and exchanging data that is human and machine-readable. It is a standard format that is often used to transfer/retrieve data from a server using an API. It is used in a wide range of web and mobile applications that rely on accessing/exchanging live data.

A JSON file is like a dictionary data structure. It is made up of two primary parts: keys and values. A key/value pair follows a specific syntax:

  • Key: Always a string enclosed in quotation marks
  • Value: Can be a string, number, Boolean expression, array, or object

Complex data structure can be created using JSON by combining {dictionaries} and [arrays].

medals.json

Before attempting this challenge you will need to familiarise yourself with the structure of the provided JSON file: medals.json

Within this file, the main key is “athletes”. Its value is an array of all the medallists of the Paris 2024 Olympics. Each medallist is stored as a dictionary with 4 keys:

  • name (Lastname firstname): e.g. Marchand Leon
  • gender: e.g. M
  • country: e.g. France
  • medals: An array of all the medals won by this athlete. Each medal within this array is another dictionary consisting of four keys:
    • discipline: e.g. Swimming
    • medal: e.g. Gold
    • event: e.g. Men’s 200m Butterfly
    • date: e.g. 2024-07-31

Here is an extract of the medals.json file showing the data for the first two athletes: Yufei Zhang who won 6 medals for China and Leon Marchand who won 5 medals for France.

{
  "athletes": [
    {
      "name": "Zhang Yufei",
      "country": "China",
      "gender": "F",
      "medals": [
        {
          "discipline": "Swimming",
          "medal": "Bronze",
          "event": "Women's 4 x 100m Medley Relay",
          "date": "2024-08-04"
        },
        {
          "discipline": "Swimming",
          "medal": "Bronze",
          "event": "Women's 4 x 100m Freestyle Relay",
          "date": "2024-07-27"
        },
        {
          "discipline": "Swimming",
          "medal": "Bronze",
          "event": "Women's 50m Freestyle",
          "date": "2024-08-04"
        },
        {
          "discipline": "Swimming",
          "medal": "Silver",
          "event": "Mixed 4 x 100m Medley Relay",
          "date": "2024-08-03"
        },
        {
          "discipline": "Swimming",
          "medal": "Bronze",
          "event": "Women's 100m Butterfly",
          "date": "2024-07-28"
        },
        {
          "discipline": "Swimming",
          "medal": "Bronze",
          "event": "Women's 200m Butterfly",
          "date": "2024-08-01"
        }
      ]
    },
    {
      "name": "Marchand Leon",
      "country": "France",
      "gender": "M",
      "medals": [
        {
          "discipline": "Swimming",
          "medal": "Gold",
          "event": "Men's 200m Breaststroke",
          "date": "2024-07-31"
        },
        {
          "discipline": "Swimming",
          "medal": "Gold",
          "event": "Men's 400m Individual Medley",
          "date": "2024-07-28"
        },
        {
          "discipline": "Swimming",
          "medal": "Gold",
          "event": "Men's 200m Individual Medley",
          "date": "2024-08-02"
        },
        {
          "discipline": "Swimming",
          "medal": "Bronze",
          "event": "Men's 4 x 100m Medley Relay",
          "date": "2024-08-04"
        },
        {
          "discipline": "Swimming",
          "medal": "Gold",
          "event": "Men's 200m Butterfly",
          "date": "2024-07-31"
        }
      ]
    }
  ]
}

Python Code

To be able to read and extract data from our JSON file using Python, we will use the json library. Here is an example of how to use Python code to load the JSON data from the medals.json file. We can then perform a basic linear search to retrieve all the medallists from Great Britain.

import json
 
# load JSON data from file
with open('medals.json','r') as file:
    data = json.load(file)

# Perform a linear search using the JSON data
athletes = data["athletes"]
for athlete in athletes:
    if athlete["country"]=="Great Britain":
       print(athlete["name"])

Let’s use this code to enable the end-user of our program to list all the medallists for their chosen country.

Your Task:

Your task consists of adding extra functions to the above code to perform the following:

     List all the athletes for a given country who won at least one gold medal
     Ask the end-user to enter a discipline. List all the medallists for this discipline.
     Ask the end-user to enter the name of an athlete. The program should list all the medals won by this athlete.
unlock-access

Solution...

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

Online Python IDE

Try this Online Python IDE (Integrated Development Environment) to help you code in Python within your web-browser. The main benefit of using an online IDE is that you will not need to install anything on your computer. Your Python code is interpreted and executed within you web browser.

With this IDE, it is not possible (yet!) to save your code online. You can however use the download button to save your files locally.

This IDE includes some built-in libraries that you can import in your projects including:

  • Turtle library (import turtle)
  • Random library (import random)
  • Time library (import time)
  • Math library (import math)

Try it yourself:

To access this IDE directly from your web-browser use the following URL: https://www.101computing.net/python

Space Explorer: The Way Back Home

Space Explorer
You are onboard a spaceship lost in a distant galaxy, far far away from planet Earth. Your aim is to return to planet Earth by using teleportation gates (black holes) to jump from one galaxy to another until you can reach planet Earth. Follow the instructions given to locate these black holes. But be aware, space is a dangerous environment. If you fail to follow the given instructions or if you hit an asteroid or a planet, your shape ship will be lost in space forever!

To complete this activity you will need to use the arrow keys on your keyboard to go North, East, South or West.
Arrow Keys

Click on the picture below to access this activity.
Space Explorer - The Way Back Home

The Lost Treasures of Pirate Island


Be the captain of your own pirate ship and sail the seven seas to find the 32 lost treasures of pirate island. Follow the instructions given to locate these treasures. But be aware, the sea is dangerous and its storms can be terrible. If you fail to follow the given instructions or if you hit a rock or an island, your ship will sink to the bottom of the deep blue sea!

To complete this activity you will need to use the arrow keys on your keyboard to go North, East, South or West.

Click on the picture below to access this activity.

Cryptic Puzzles – Computer Networks

Before attempting to solve this challenge, you should familiarise yourself with the different types of clues that cryptic definitions can be based on. Effectively, the definitions given in a cryptic crossword, will almost never be a literal meaning of the answer you are looking for. Instead, they will be based on a wordplay. When looking at a definition, you will first need to try to locate the two main hints which are:

  1. An exact definition or synonym, in much the same way as a conventional crossword clue. This can appear either at the start or at the end of the definition.
  2. Some sort of wordplay. There are many different types of wordplay that can be used. Sometimes an indicator term (a specific expression or word) will lead you to the type of wordplay that is being used.

Let’s investigate some of the most common types of cryptic crossword definitions:

Double DefinitionAnagramsAcrosticHidden WordsReversalHomophonesCharadesDeletionCrypticComplex

Double Definition:

When the clue consists of two different meanings of the same answer.
Double Definition

Anagrams:

With these clues you will have to jumble up the letters from the clue to find the answer.
Anagrams

Acrostic:

These sorts of clues means that you will have to take some of the letters (e.g. the first letter of each word, or the last letter, or every odd letter, etc.)
Acrostic Definition

Hidden Words:

When the answer is actually included within the clue itself! you just need to spot it!
Hidden Words

Reversal:

When you need to read a word or expression backwards, from right to left.
Reversal

Homophones:

The answer you have will sound similar to the actual answer you are looking for! You may have to say it out loud to find it!
Homophones

Charades:

Charades will involve joining several parts of words together to get to the final answer.
Charades

Deletion:

On occasion you will need to remove one or several letters from the clue to get to the answer.
Deletion

Cryptic Definition:

These can be quite challenging, using a confusing definition sometimes purposefully given in a somewhat misleading way.
Cryptic Definition

Complex Definition:

When you start combining several techniques within the same definition!
Complex Definition

Let’s have a go at solving these cryptic clues all based around Computer Networks terminology:

unlock-access

Solution...

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

Computer Science – Cryptic Crossword #02

Here is our second cryptic crossword for computer scientists! You can access our first cryptic crossword on this page.

Before attempting to solve this challenge, you should familiarise yourself with the different types of clues that the crossword definitions can be based on. Effectively, the definitions given in a cryptic crossword, will almost never be a literal meaning of the answer you are looking for. Instead, they will be based on a wordplay. When looking at a definition, you will first need to try to locate the two main hints which are:

  1. An exact definition or synonym, in much the same way as a conventional crossword clue. This can appear either at the start or at the end of the definition.
  2. Some sort of wordplay. There are many different types of wordplay that can be used. Sometimes an indicator term (a specific expression or word) will lead you to the type of wordplay that is being used.

Let’s investigate some of the most common types of cryptic crossword definitions:

Double DefinitionAnagramsAcrosticHidden WordsReversalHomophonesCharadesDeletionCrypticComplex

Double Definition:

When the clue consists of two different meanings of the same answer.
Double Definition

Anagrams:

With these clues you will have to jumble up the letters from the clue to find the answer.
Anagrams

Acrostic:

These sorts of clues means that you will have to take some of the letters (e.g. the first letter of each word, or the last letter, or every odd letter, etc.)
Acrostic Definition

Hidden Words:

When the answer is actually included within the clue itself! you just need to spot it!
Hidden Words

Reversal:

When you need to read a word or expression backwards, from right to left.
Reversal

Homophones:

The answer you have will sound similar to the actual answer you are looking for! You may have to say it out loud to find it!
Homophones

Charades:

Charades will involve joining several parts of words together to get to the final answer.
Charades

Deletion:

On occasion you will need to remove one or several letters from the clue to get to the answer.
Deletion

Cryptic Definition:

These can be quite challenging, using a confusing definition sometimes purposefully given in a somewhat misleading way.
Cryptic Definition

Complex Definition:

When you start combining several techniques within the same definition!
Complex Definition

The following Cryptic Puzzle is based on Computer Science Terminology (from the A Level Computer Science Specification).
Computer Science Cryptic CrosswordOpen Cryptic Crossword Puzzle in a New Window Spoiler alert… You can click below to reveal few tips to help you if you are completely stuck:

Tip #1
  • At least one definition in this puzzle will require you to use roman numerals
Tip #2
  • In tennis, the word “love” refers to a score of 0. Therefore, in a cryptic clue, the word love can be replaced with letter O.
Tip #3
  • In cricket, the word “duck” refers to a score of 0. Therefore, in a cryptic clue, the word love can be replaced with letter O.
Tip #4
  • In a cryptic puzzle, sailors can be a reference to the Royal Navy!
Tip #5
  • Extraordinary, broken or engineer are all indicator terms for an anagram definition!


Computer Science Cryptic CrosswordOpen Cryptic Crossword Puzzle in a New Window

unlock-access

Solution...

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

Ice Cream Price Calculator

Your local ice cream shop would like to set up a touchscreen tablet on the counter for their customers to customise their ice cream order and automatically calculate the cost of their ice cream.

Here are the options available when ordering an ice cream:

The new system will need a computer program to let the customer pick up their options for their ice cream. The customer should be able to specify:

     Whether they would like their ice cream to be served in a cup or on a cone
     How many scoops they would like to order (between 1 and 4)
     Whether they would like to add a flake
     Whether they would like to add some chocolate sprinkle
     Whether they would like to add a strawberry coulis

Based on the user inputs and the price list provided above, the system should automatically calculate and display the total price of the chosen ice cream.

Step 1: Draw a Flowchart for your algorithm

Before attempting to complete the code for this task, grab a piece of paper and draw the flowchart to identify the key inputs, decisions and calculations for your algorithm.

Alternatively, you can also create your flowchart online:
Flowchart Studio

Step 2: Complete the Python Code

Complete the Python code below.

Step 3: Add validation checks

To make your program more robust, add some validation rules on your inputs so that:

     The user can only enter one of the two options: Cup or Cone when selecting the container for their ice cream.
     The user can only enter a number between 1 and 4 when entering the number of scoops.
     The user can only enter Yes or No when asked whether they would like to add a flake, chocolate sprinkle or strawberry coulis.

You can find out more about implementing validation checks in Python using this page (input validation tab).

Step 4: Test Plan

Once your code is complete, test it using the following test plan to make sure all your calculations are correct!

Test # Input Values Expected Output Pass / Fail
#1 Container: Cone
Number of Scoops: 2
Toppings: Chocolate sprinkle
Ice Cream Price: £3.10
#2 Container: Cup
Number of Scoops: 3
Toppings: Flake and Strawberry Coulis
Ice Cream Price: £4.50
#3 Container: Cup
Number of Scoops: 6
Toppings: None
Please enter a number of scoops between 1 and 4
#4 Container: Cup
Number of Scoops: 1
Toppings: None
Ice Cream Price: £1.50
unlock-access

Solution...

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