More results...

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

RGB Converter

rgb-color-code-ballsDid 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)

Graphic designer and software programmer sometimes prefer to use another notation based on hexadecimal RGB code where each of the three decimal values are converted into a two-digit hexadecimal code, resulting in a 6-digit (3×2) hexadecimal code. For instance:

  • Red is #FF000
  • Green is #00FF00
  • Blue is #0000FF
  • Yellow is #FFFF00
  • Orange is #FFA500

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

The aim of this challenge is to write a program to perform decimal RGB to hexadecimal colour codes conversion and vice-versa.

Your Code


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 Converter using Python

Did You Know?

Everything that is stored on a computer is stored as binary code. Binary code is made of bits (0 or 1). We often use Bytes to store data. A Byte is made of eight bits and can be used to store any whole number between 0 to 255. Check it yourself, click on the binary digits to create your own binary number:

1286432168421
11111111

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255


Python Challenge


The purpose of this challenge is to write a Python script to convert a Binary number into denary and vice versa. To do so we will use the concept of binary left and right shifts as explained below.

Binary Left Shift


A binary left shift is used to multiply a binary number by two. It consists of shifting all the binary digit to the left by 1 digit and adding an extra digit at the end with a value of 0.
binary-left-shift

Binary Right Shift


A binary right shift is used to divide a binary number by two. It consists of shifting all the binary digit to the right by 1 digit and adding an extra digit at the beginning (to the left) with a value of 0.
binary-right-shift

Python Code


unlock-access

Solution...

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

BBC micro:bit – Hogwarts Sorting Hat

hogwarts-sorting-hatIn the Harry Potter series of novels written by British author J. K. Rowling, The Sorting Hat is a magical hat at Hogwarts that determines which of the four school Houses each new student belongs most to. These four Houses are Gryffindor, Hufflepuff, Ravenclaw, and Slytherin.

In this challenge we are going to write a program for the BBC micro:bit to act as the sorting hat. Whenever a students from Hogwarts school of Witchcraft and Wizardry will shake the BBC micro:bit, a message will appear telling them which house they belong in.

You will need to use the micro:bit website to create the code using the JavaScript Block Editor.

micro-bit-logo

Block Programming


Here is the code to implement the Sorting Hat algorithm:
harry-potter-sorting-hat-BBC-microbit-javascript-code

Resetting the Sorting Hat


Add the following code to reset the Sorting Hat when either button A or button B is pressed:
harry-potter-sorting-hat-reset-code

Tagged with: ,

Password Checker

password-checkerFor this challenge we will write a program where the end-user has to type a password. The program will then return a score to tell the end-user how secure their password is based on the following criteria:

Criteria Score
The password contains lowercase and uppercase characters. +10 pts
The password contains numbers and letters. +10 pts
The password contains at least one punctuation sign. +5 pts
The password is at least 8 characters long. +5 pts

Video Tutorial

Complete the code


We have started the code but have only implemented the first two criteria. Your task is to implement all 4 criteria.

Test Plan


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Actual Output
#1 Password: mypassword 5 pts
#2 Password: myPassWord 15 pts
#3 Password: myPassWord123 25 pts
#4 Password: #myPa$$Word123 30 pts
#5 Password: ?gB;45#wq2 30 pts
#6 Password: (leave blank) 0 pts

Extension Task


How could you tweak your code to implement the following rules:

Criteria Score
The password contains at least 2 lowercase and at least 2 uppercase characters. +15 pts
The password contains at least 2 numbers: +15 pts
unlock-access

Solution...

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

Happy Birthday!

happy-birthdayFor this challenge we are going to write a Python program which will ask the end-user to enter their date of birth in the following format: dd/mm/yyyy.

The program will then calculate and display the following information:

  • The age of the user,
  • The number of days the user has lived for,
  • The week day (Monday to Sunday) corresponding to their Date of Birth,
  • The number of days left until the user’s next birthday,
  • A “Happy Birthday” message if today is the user’s birthday!

Learning Objectives


By completing this challenge you are learning various techniques to manipulate and format dates. These include formating a date in the dd/mm/yyyy format, retireving today’s date or calculating the difference in days or years between two dates.

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: ,

Days Until Summer

calendar-date-time

Did you know?

Summer starts on the Summer Solstice which, in the Northern hemisphere, is the 21st of June. It ends three months later, on September the 22nd, a date known as known as Autumnal equinox, when the Autumn season starts.

For this challenge you will write a Python script that retrieves today’s date to find out if we are in Summer or not. If not, it will calculate the number of days until next Summer, which could be in the same calendar year or in the following calendar year (in case we have already passed this year Summer season).

To do so we will reuse and adapt the following code used to calculate the number of days until next Christmas. Your task is to analyse how this code works to then make the necessary amendments to:

  • Find out if we are already in the Summer season,
  • if, not find out if this year Summer is already past,
    • if it has, calculate the number of days left till next year Summer,
    • otherwise, calculate the number of days till this year Summer.

Python Code


unlock-access

Solution...

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

Which Season?

which-season-autumn-date-time

Did you know?:


Though we all agree that a calendar year is divided into four seasons, people sometimes disagree on the dates when these seasons start or finish. Many bodies, for example meteorologists, adopt a convention for the purpose of presenting statistics by grouping the twelve months of the year into four three-month seasons, for example March, April and May being taken as Spring.

In this case the seasons could be defined as follows:

From To Season
1st September 30th November Autumn
1st December 28/29th February Winter
1st March 31st May Spring
1st June 31th August Summer

Other scientists and astronomers prefer to define the four seasons based on astronomical events known as the equinoxes and the solstices. The equinoxes occur in March and September when the Sun is ‘edgewise’ to the Earth’s axis of rotation so that everywhere on Earth has twelve hours of daylight and twelve hours of darkness. The solstices occur in June and December when the Earth’s axis is at its extreme tilt towards and away from the Sun so at mid-day it appears at its highest in one hemisphere and at its lowest in the other.

The exact dates for the solstices and equinoxes vary from one year to the other but are around the 21st of the months mentioned above.

From To Season
21st September 20th December Autumn
21st December 20th March Winter
21st March 20th June Spring
21st June 20th September Summer

Your Challenge:


Write a computer program that retrieves today’s date. The program should then display the season for this date based on the astronomical definition of the four seasons.

We have started the code for you but have only worked out the dates for Spring. You can now complete the code to cater for all four seasons.

unlock-access

Solution...

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

Love Match Calculator

love-match-calculator
For this challenge we will write a program that will prompt the user to enter two first names. The program will then calculate and return a Love Match Score based on the following criteria:

Criteria Score
Both first names have the same numbers of letters. +20 pts
Both first names start with a vowel. +10 pts
Both first names start with a consonant. +10 pts
Both first names have the same number of vowels. +12 pts
Both first names have the same number of consonants. +12 pts
Both first names contain at least a “l”, “o”, “v” or “e”. +7 pts

Complete the code


We have started the code but have only implemented the first two criteria. Your task is to implement all 6 criteria.

Test Plan


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Actual Output
#1 Firstname #1: Luna
Firstname #2: Evan
51 pts
#2 Firstname #1: Alice
Firstname #2: Nolan
27 pts
#3 Firstname #1: Maya
Firstname #2: Leo
22 pts
#4 Firstname #1: Nora
Firstname #2: Lillian
17 pts
#5 Firstname #1: Ivy
Firstname #2: Eli
61 pts
#6 Firstname #1: Sofia
Firstname #2: Logan
37 pts
unlock-access

Solution...

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

Lossless Compression

The purpose of lossless compression is to reduce the amount of storage space needed to save some information, without losing any information hence without losing quality.

Lossless compression can be used to store text-based information in a more effective way.

lossless-compression-lego-towerLook at the above text file used to store the pattern of a lego tower. Can you think of a better way to store this information?


Method #1: Run-length Encoding


Run-length encoding (RLE) is a very simple form of lossless data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count.

lossless-compression-lego-tower-2
Apply run-length encoding to the lego tower:


Method #2: Dictionary Coding


Dictionary coding, aka substitution coding, is a lossless data compression approach which consists of searching for matches between the text to be compressed and a set of strings contained in a data structure (called the ‘dictionary’) maintained by the encoder. When the encoder finds such a match, it substitutes a reference to the string’s position in the data structure.

For instance in we could use the following dictionary:

  • B -> Blue
  • G -> Green
  • R -> Red
  • Y -> Yellow

lossless-compression-lego-tower-4
Apply dictionary codeing to the lego tower:


Combining Both Techniques:


We can combine both Dictionary Coding and Run-Length Encoding to compress out file even further:
lossless-compression-lego-tower-5

Apply both techniques to your lego tower:





Lossless compression of bitmap pictures


We have applied lossless compression to a text file. How could we use this type of compression for picture files?

Domain Name Server

dns-onlineDomain Name Servers (DNS) are the Internet’s equivalent of a phone book. They maintain a directory of domain names and translate them to numerical IP addresses. These IP addresses are used to identify and locate the web-servers on the Internet network.

Domain names such 101computing.net are easy for people to remember. Computers however access websites based on IP addresses, hence the needs for domain name servers: when typing a website address in your web browser such as http://www.101computing.net, your request will reach a domain name server that will convert the domain name part of the address (101computing.net) into its matching IP address.

DNS-Domain-Name-Server

Your Challenge


For this challenge we are going to create a Python script to “act as a domain name server”. The script will ask the user to enter a domain name, search for this domain name within its own directory of domain names using a linear search and if found, return the matching IP address.

Our DNS script will use a text file with a short list of just 32 domain names and IP addresses. This data is organised as follows:

Domain Name,IP Address

You can download this text file:

TextFiledns.csv

You can find out more about how to access text files in Python by reading this blog post.

Method 1: Linear Search


To find the requested domain name you will first implement a linear search: your algorithm will need to read the dns.csv file one line at a time and check if the domain name is a match.

Below is the flowchart of a linear search:
linear-search-algorithm

Method 2: Binary Search


You may have noticed that the list of domain names in the dns.csv file is sorted in alphabetical order. This is a key requirement to implement a binary search, a more efficient approach to search through a sorted set of data.

Below is the flowchart of a binary search:
binary-search-algorithm

Did you know?


Currently most IP addresses are using the IPv4 format, based on 4 numbers between 0 and 255 sepearated by a dot.
ipv4

The IPv4 protocol however will soon be upgraded to the IP version 6 (IPv6) internet protocol. The reason for this upgrade is that there is need to generate more IP addresses to allow more devices (webservers, desktops, laptops, smartphones, smartwatches and other connected objects) to have a unique IP address on the network. An IPv6 address is based on 128 bits (instead of 32 bits for an IPv4 address).
ipv6

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: , , , ,
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.