More results...

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

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

UPC Barcode & Check Digit Calculation

UPC-A-BarcodeA barcode is an optical, representation of data that can easily be scanned by a barcode reader.

A barcode is used to store a number such as the product code of a product for sale in a shop, or the ISBN number of a book. The barcode you scan in a shop most likely uses the UPC (Universal Product Code) format which means that it consists of 12 numerical digits (0 to 9).

With a UPC barcode, the last digit is called the check digit. The check digit is used to make sure a barcode has been entered (typed) or scanned correctly to minimize human errors or scanning errors.

The check digit is a result of a complex calculation based on the 11 first digits of the barcode. Every time a barcode is scanned, the computer completes this calculation again using the first 11 digits to calculate the check digit. it then compares this with the 12th digit of the barcode. If these two are the same, the barcode scanned is most likely valid. If they are diffrent the scanner will beep to indicate that the barcode was not scanned properly.

The check digit is a fairly complex calculation that is performed in 3 steps as follows:

  1. Add the digits in the odd-numbered positions (first, third, fifth, etc.) together and multiply by three.
  2. Add the digits (up to but not including the check digit) in the even-numbered positions (second, fourth, sixth, etc.) to the result.
  3. Take the remainder of the result divided by 10 (modulo operation) and if not 0, subtract this from 10 to derive the check digit.

Check Digit Calculation

check-digit-calculation

Check Digit Validation

Your challenge consists of writing a Python program that will receive a 12-digit UPC barcode (11 digits + 1 check digit). Your Python script will then calculate the expected check digit matching the 11-digit product code. If this calculated check digit matches the 12th digit of the barcode, your program will output “Valid barcode”, if not it will output “Invalid barcode” on the screen.

Invalid Barcode?

You will then test your program with the following 6 barcodes. One of them is invalid! Use your program to find it:

# Barcode UPC-A Valid or Invalid?
#1 barcode-upc-a-1 123456789012
#2 barcode-upc-a-2 796483659834
#3 barcode-upc-a-7 572451780690
#4 barcode-not-upc-a-3 967483921543
#5 barcode-upc-a-4 485932587605
#6 barcode-upc-a-5 483025016933
#7 barcode-upca-a-6 659047763326
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 Login Script

loginA lot of computer systems rely on the need for the user to login using a username and password. This form of authentication is used to uniquely identify a user and give them access to the relevant information on the system.

The aim of this challenge is to create our own authentication process. We will break up this challenge in several steps:

Step 1: Login Screen


Create a login screen, where the user is asked to enter their username and password. Compare these values with a valid username and password stored within your code.

If the user enters the right username and password, the program should output a message saying “You are logged in!”. If not the program should display the message “Wrong username or password!”.

Step 2: Multiple Attempts


Amend your code so that if the user enters the wrong username and password they are being asked again. The user should have 3 attempts. If after three attempts their username and password is still wrong the program should end.

Step 3: Using a text file


Hardcoding the username and password in the code itself is not good practice as it does not allow users to create new usernames and passwords or to amend their password. It also restricts the number of usernames and password you can use. Instead usernames and password should be stored in a separate file so that usernames and passwords can easily be added or updated.

We have created a text file with the list of the 10 usernames and passwords. This data is organised as follows:

username,password

You can download this text file:

TextFileusernames.txt

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

Create a login script that checks the user’s username and password to see if they match any entry stored in the username.txt file.

Step 4: Sign Up


Before the login screen, give the option for a new user to sign up by entering their first name, last name and password. The system should work out the username (first letter of first name followed by last name) and store the username and password in the usernames.txt text file. If another user with the same username already exists, the program should add a number at the end of the username. For instance, “tswift2” would be the username of Tom Swift as there is already one username “tswift” for Taylor Swift in the text file.

Also you should add some validation routines to ensure that the user does not leave the first name or the last name fields blank. If they do, an error message should appear saying: “You must provide both your first name and last name!”.

Step 5: Change My Password


Once logged in the username should be able to change their password. Make sure that a logged in user has to enter their new password twice and that the program check that both entries are the same before updating their password.

Step 6: Strong Password Validation


Once a user enters a new password or updates their existing password the program should check that the password is a secure password by checking some, if not all of the following conditions:

  • The password has to be at least 8 characters long,
  • The password has to include uppercase letters and lowercase letters,
  • The password has to letters and numbers,
  • The password has to include at least one punctuation sign.

Step 7: Are You Human?


A CAPTCHA is a type of challenge-response test used in computing to determine whether or not the user is human.

Web-bots are computer programs that can be used to try every single possible password to try to get access to a password protected system. We can stop web-bots by asking a question that web-bots may not understand. Add a CAPTCHA to your login form to prevent web-bots trying to access your website.

Easy CAPTCHA: The computer displays a random 3 digit number on the screen and asks the user to enter this number when login in.

Complex CAPTCHA: The computer displays a random arithmetic question such as “what is 7+3?”. The user has to answer this question correctly when login in.

unlock-access

Solution...

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

Question Time – Relational Databases


– Online Database –
– SQL Activities –

Feeling confident with your computing knowledge of Relational Databases?

Spend a few minutes to answer or research the following questions:


?
What are tables used for in a relational database?


?
How do tables, records and fields relate to each other?


?
What are the main data types when storing data values?


?
What is the purpose of a primary key?


?
What is the purpose of a foreign key?


?
What are the three types of relationship in a database?


?
Using a school database can you give an example of each type of relationship?


?
Why is the customer name not a good field to use as a primary key?


?
Why is meant by an autoNumber or autoIncrement field?


?
When storing data about cars for a car dealer database, what field could be used as a primary key?


?
Why is it sometimes necessary to create a link table?


?
What is the difference between an entity and a table?


?
What does the acronym CRUD stands for?


?
What language is used to run queries in a database? What does it stand for?


?
What are the main keywords used in the SQL language to start a CRUD query?


?
In a database what is meant by redundant data?


?
What is the purpose of normalisation?


?
Can you describe the characteristics of a relational database in 1NF, 2NF, 3NF.


?
What is meant by “flat file”?


?
What is meant by atomic data?


?
What is meant by referential integrity?


?
In a client-server web application, where is the relational database stored?


?
What is meant by “SQL injection”?

Tagged with:

BBC micro:bit – Automated Car Park Display

car-park-signOur aim is to use the BBC micro:bit to create an automated Car Park Display to inform drivers of the number of empty spaces left in a car park.

Our system should:

  • Be initialised with the number of available spaces in the car park set to 20 and the car park will be empty when the program is started.
  • When the car park is empty the micro:bit should display a scrolling message saying “Car park is empty”
  • car-park-empty

  • To enter the car park, the driver has to press the A button of the micro:bit. The display should then changes to calculate and display the number of empty spaces left: e.g. Scrolling text : “15 spaces left”.
  • car-park-15-spaces-left

  • When a car leaves the car park, they will press the B button of the micro:bit. The display should then changes to refresh the number of empty spaces left.
  • If the car park is full, the micro:bit should display the scrolling text: “No entry – Car park is full”. Drivers should not be able to enter the car park. Instead, should the A button be pressed the display should say “No entry – Car park is full”.
  • car-park-no-entry

Use the microbit.org website to get started!

Solution

We will complete this project in 4 blocks of code.

First let’s initialise two variables:

  • maxCapacity to store the total number of spaces of the car park. (e.g. 20)
  • emptySpaces to store the total number of empty spaces of the car park. To start with we will assume the car par is empty so we can set emptySpaces to the same value as maxCapacity.

Then we will decrement the number of empty spaces by 1, everytime the A button is being pressed. (A car enters the car park), making sure that we only let cars in if the number of empty spaces is greater than 0. (There is at least on empty space).

Using a similar approach, we will increment the number of empty spaces by 1 everytime the B button is pressed (A car leaves the car park)

Finally, depending on the number of empty spaces in the car park, we will display the relevant message as scrolling text to inform users of the number of empty spaces in the car park.

unlock-access

Solution...

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

Caesar Cipher

In cryptography, a Caesar cipher, also known as shift cipher, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

The action of a Caesar cipher is to replace each plaintext letter with a different one a fixed number of places down the alphabet.

Caesar_cipher_left_shift_of_3

The cipher illustrated above uses a left shift of three, so that each occurrence of E in the plaintext becomes B in the ciphertext.

The transformation can be represented by aligning two alphabets; the cipher alphabet is the plain alphabet rotated left or right by some number of positions. For instance, here is a Caesar cipher using a left rotation of three places, equivalent to a right shift of 23 (the shift parameter is used as the key):

Plain:  ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW

When encrypting, a person looks up each letter of the message in the “plain” line and writes down the corresponding letter in the “cipher” line.

Plaintext:  THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD

Deciphering is done in reverse, with a right shift of 3.

The encryption can also be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,…, Z = 25.[2] Encryption of a letter x by a shift n can be described mathematically as,

caesar-cypher-encoding

Decryption is performed similarly,

caesar-cypher-decoding

The Caesar cipher is named after Julius Caesar, who used it, more than 2000 years ago, to protect messages of military significance.

julius-caesar

Vercingetorix throws down his arms at the feet of Julius Caesar. Painting by Lionel Royer – Musée CROZATIER du Puy-en-Velay – France, Public Domain.

Caesar Cipher Wheel


A cipher wheel is a tool used to help decipher a message encrypted using the Caesar cipher:

Encrypted Message


Use a Python program to decode the following secret message:

caesar-encode-message
N qtaj uwtlwfrrnsl zxnsl Udymts!
Key: right shift by 5 characters


unlock-access

Solution...

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

Access Rights using Binary Masks

Imagine a building with 8 rooms.

Binary-Mask-Room-Layout

Each room is fitted with a card reader used to give access or not to different members of staff.
Each member of staff has a card giving them access to some of the rooms.
The card is used to store an access code:

Access-Card-XL-1

This card gives access to:

  • Room 3,
  • Room 5,
  • Room 8.

Hence the Access Code: 00101001

Task 1: Access Denied!


Complete the following table to show which rooms these cards will give access to:

Access Card Room Access
Binary-mask-access-card-1
Binary-mask-access-card-2
Binary-mask-access-card-3
Binary-mask-access-card-4

Task 2: Centralised Override! – AND Mask


The site manager can control access to all the rooms by disabling or enabling access to specific rooms. He can do so by setting an access code mask consisting of 8 bits.
For instance the access mask 00001111 would mean that only rooms 5,6,7,8 are accessible (by authorised card holders) while rooms 1,2,3 and 4 are completely locked.

The locking system at the door uses both the access code of the staff member’s card and the building access mask to decide if a staff member can unlock a room:

Access-Card-AND-Mask

This means that this member of staff can only access room 5 and room 8. This operation consists of applying an AND mask to determine the resulting room access code.

Considering the following Access Mask:

00110011

Perform the AND mask filter to work out which rooms these staff cards will give access to.

Access Card Room Access
Binary-mask-access-card-1
Binary-mask-access-card-2
Binary-mask-access-card-3
Binary-mask-access-card-4

Task 3: Multiple Cards Access! – OR Mask


On specific occasions, a staff member is allowed to borrow a card from one of their colleagues. This may give them access to additional rooms. Using an OR mask between two access cards code we can figure out all the rooms an employee with two cards can have access to.

Access-Card-OR-Mask

Use an OR mask with the following cards access code to determine which rooms these sets of two cards will give access to:

Access Card 1 Access Card 2 Room Access
Binary-mask-access-card-1 Binary-mask-access-card-2
Binary-mask-access-card-1 Binary-mask-access-card-4
Binary-mask-access-card-3 Binary-mask-access-card-2
Binary-mask-access-card-4 Binary-mask-access-card-2
Tagged with:

Responsive Website Layout

When designing a website, you have to consider the different sizes of screens of your internet users. These may access your website using a computer (desktop/laptop), a tablet, a smartphone, a smart TV…

A responsive website is a website where the layout adapts to the size of the screen.

On a large screen, the layout may include a header, a footer, several columns, left and right panels. A responsive layout can then adapt to smaller/narrower screens such as smartphones by adopting a linear layout (where all the sections mentioned above appear one after the other).

responsive-layout-website-design

Using CSS it is possible to apply different sizes and positions to different sections of the website based on the size of the screen.

If you have used one of the layout from “HTML – Website Layout” then you can add the extra CSS provided below to make your website responsive.

@media screen and (max-width: 1040px) {
	BODY {
		margin: 20px 20px 20px 20px;
	}
	
	.page, .pageHeader, .pageContent, .pageLeftPanel, .pageRightPanel, .pageFooter {
		width: 100%;
	}
	
	.pageContent, .pageLeftPanel, .pageRightPanel {
		min-height: auto;
	}

	IMG {
		max-width: 100%;
	}
}

A quick approach to test if your website is responsive is to resize your bowser window to the size of a smartphone and see how your website behaves.

Other aspects of a website can also adapt to the size of the screen. These includes pull-down navigation menus, font sizes, picture sizes, interactive elements such as tabs, accordion menus… However these can sometimes be trickier to implement.

Video Tutorial

Tagged with: ,