More results...

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

Boggle Challenge

boggleBoggle is a word game based on a 4×4 grid of 16 letters. Each time the game is played a new grid is generated. In the real game this is done by shaking a cube that contains 16 letter dice. The The aim of the game is to find words that can be constructed from sequentially adjacent letters from the 4×4 grid. “Adjacent” letters are those horizontally, vertically, and diagonally neighbouring. Words must be at least three letters long, may include singular and plural (or other derived forms) separately, but may not use the same letter from the grid more than once per word.

A scoring system can be used based on the number of words identified and by adding the number of letters in each word.

For this challenge you will re-create a single-player game of Boggle using a step by step approach.

Step 1: Generating and displaying a random 4×4 grid


Your first task is to write a script that will randomly generated a 4×4 grid containing 16 letters randomly picked from the alphabet.

Note that you can use ASCII values for letter A (ASCII value 65) to Z (ASCII value 90) to generate a random letter as follows:

import random
letter=chr(random.randint(65,90)) #Generate a random Uppercase letter (based on ASCII code)

A 4×4 grid could be defined as a 2D array (a list of lists in Python). For instance, the following code uses two nested for loops to generate a 2D array filled with 16 letters “A”.

grid = [] 
for row in range(0,4):
   grid.append([])
   for col in range(0,4):
       grid[row].append("A")

print(grid)

Your task is to adapt the above code to fill the grid with random letters rather than just using letter “A”.

Then you will need to complete the code to display the content of the grid using the right format: the output should look like a 4×4 grid. (Tip: you will need to use nested loops once more time!)

Step 2: Inputting and validating words


The next step is to let the user input a word that they spotted on the grid.
You will need your program to decide if the word is a valid word that can be generated using adjacent letters from the grid. (and making sure the same letter cannot be used mote than once).

Step 3: Scoring system


Finally you may let the user enter several words, and calculate a total score by adding the length of all valid words that the user will spot (making sure they do not enter the same word more than once).

Tagged with:

Computer Networks Crossword

crosswordAre you confident with your knowledge of network design concepts? Can you identify the purpose of the main network components used to set up a LAN or a WAN?

You can find out more about key network design concepts on this page..


Computer NetworksOpen 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
Tagged with:

What 3 Words Localisation

what-3-word-localisationWhat3words is a geocode system used to communicate a location on planet Earth using only 3 words instead of using complex longitude and latitude coordinates. What3words have assigned each 3m square in the world a unique 3-word address that will never change.

The what3words grid contains 57 trillions 3×3 squares to cover the whole Earth surface (510 million km2) and a dictionary of 40.000 words to create enough combinations of 3 words to assign a unique address to each square (40.0003 = 64 trillions).

For instance, Big Ben, London UK – which is located at Longitude: -0.12461, Latitude:51.500755 – has a 3-word address of: teams.living.bucket

What3words believe that this approach can be used to communicate very specific locations (with a 3-meter accuracy) in an easy, human friendly way. Emergency services in the UK are for instance recommending every smartphone user to download the what3words app as it can be used to speed up the localisation process in case of an emergency.

You can find out more about the what3words initiative on: https://what3words.com.

What3words API


What3words offer developers an API to integrate the conversion of 3-word addresses into longitude/latitude coordinates and vice versa into other products/systems. You can read more about this API on https://docs.what3words.com/api/v3/.

The API enables you to make a request by passing for instance a 3-word address. It will then return the matching longitude/latitude coordinates using the JSON format.

JSON Data


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/

You can see what the JSON data returned by the API looks like:

{
    "country": "GB",
    "square": {
        "southwest": {
            "lng": -0.195543,
            "lat": 51.520833
        },
        "northeast": {
            "lng": -0.195499,
            "lat": 51.52086
        }
    },
    "nearestPlace": "Bayswater, London",
    "coordinates": {
        "lng": -0.195521,
        "lat": 51.520847
    },
    "words": "filled.count.soap",
    "language": "en",
    "map": "https://w3w.co/filled.count.soap"
}  

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 can then use this code to localise and identify the landmarks associated to the following 3-word addresses:

  • teams.living.bucket
  • walnuts.octopus.mount
  • planet.inches.most
  • tiny.loses.tree


Tagged with: ,

String Slicing in Python

String?


In computer science, a string is a piece of text or a collection of characters.
string-manipulation-1

String Length?


The length of a string represents the number of characters it contains. In pyhon you can use the function len() to find out the length of a string.

pasword = input("Enter your password:")
if len(password)<8:
   print("Your password is not long enough!")

String Slicing?


string-sliceOn occasions, you will want your program to extract a few characters from a string. This is called string slicing.

You may for instance extract the first 5 characters of a phone number to retrieve the area code. Or you may need to extract the last 4 characters of a date to extract the year part.

Extracting a single character at a given position:

You can retrieve a character at a given position as follows:

string[position]

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
firstCharacter = alphabet[0]
lastCharacter = alphabet[25]

Note: The first character is always at position 0!

Extracting a substring (multiples characters) from a string:

To slice a string in python you have to think about the starting position and the ending position and use the following syntax:

string[start:end]

This syntax will extract all the characters from position start up to but not including position end.

If start is left empty, the substring will start from position 0.
If end is left empty, the substring will end at the last character of the string.

A negative start value or end value is used to identify a position (number of characters) from the end of the string. This can be useful to extract the last few characters of a string.

Try it yourself
Enter a string below and use the two handles to change the start and end position and slice your string accordingly. The resulting substring will appear in purple.

Slicing the alphabet:

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print("The first 5 letters of the alphabet are: " + alphabet[:5])
print("The last 5 letters of the alphabet are: " + alphabet[-5:])
print("The letters in between are: "  + alphabet[5:-5])

Slicing a date:

date = "05 January 2019"
day = date[:2]  #First 2 characters
year = date[-4:] #Last 4 characters
month = date[3:-5] #The remaining characters in the middle

Locating if a substring is in a string (and retrieving its position)?


You can easily find if a substring is in a string using the keyword in.

dateOfBirth = "15 January 2000"
if "January" in  dateOfBirth:
   print("You were born in January!")

You can also retrieve the exact position of a substring in a string using the find() function:

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
pos = alphabet.find("C")
print("Letter C is at position: " + str(pos))

This script would tell us that letter “C” is at position 2. (Even though it is the third letter of the alphabet). That’s because the first letter in a string is always at position 0, not 1!

Note that if the substring is not found in the string, the find() function will return the value -1.

String Concatenation?


The act of joining two strings together is called string concatenation.
string-Concatenation

In Python string concatenation is done using the + sign:

firstname = "James"
print("Hello " + firstname)

Python Code:


Python Challenge


Your challenge is write a program to ask the user to enter their school username in the following format:

  • Year Group Using two digits (e.g. “07” for year 7, “11” for year 11, “00” for staff members)
  • 1 character for their initial (first letter of their firstname)
  • The user’s lastname
  • A 2-digit code: “_S” for students, “_T” for teachers, “_A” for admin staff.

For instance the following usernames are valid usernames:


07jFox_S
09kJohnson_S
11rTaylor_S
00pJones_T
00jOliver_A

Your program should read the username and decide:

    If the username is less than 6 characters long the program should ask the user to enter a valid username.
    If the username does not contain the character “_” it should also ask the user to enter a valid username.
    If the username is valid, the program should decide if the user is a member of staff or a student.
    If they are a student the programme should find out their year group.
    The program should also display the initial of the student as well as their lastname.
    Finally the program should display whether the user is a Student, a Teacher or an Admin member of staff.
unlock-access

Solution...

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

Floating Point Binary Converter

The purpose of this challenge is to write a Python program that will receive, as an input, a binary number expressed using a normalised floating point representation (using a 5-bit mantissa and a 3-bit exponent). The program will then calculate the decimal value matching the input.

The following conversion tool will help you work out the formula used to convert a normalised floating point binary number to a decimal number.

Python Code


Extension


Adapt your code to let the user input the number of bits used for the mantissa and the number of bits used for the exponent. Your program will then use these inputs to validate and convert a binary number entered by the user.

Higher or Lower Number Game

Higher-Or-LowerFor this challenge you will design and write a program to play against the computer. The computer will display a random number between 1 and 100. The user will have to try to guess this number. For each guess the computer will inform the user if the number to guess is higher or lower than the user guess. The program will end once the user guess matches the number to guess.

Learning Objectives


By completing this challenge you are going to use selection (IF statements) and iteration (While loop). You will use comparison operators such as > , < and == to compare numbers. You will use variables to store the value of a random number and retrieve user inputs.

Task 1: Flowchart


Use our online Flowchart Studio tool to create the flowchart for this algorithm:
Online Flowchart Creator guess-the-number-while-loop-flowchart

Task #2: Complete the 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: , ,

Higher or Lower LMC Challenge

Higher-Or-LowerFor this challenge you will write a program of Guess the number (Higher or Lower?) using LMC assembly language.

Your program will be used by two users (player A and player B) as follows:

  • Ask player A to input a number between 1 and 100 (without player B looking at what player A is inputting)
  • Ask player B to guess player A’s number. For each guess, the program will give feedback to the player as to whether their guess is too high or to low.
  • Let player B carry on guessing till they guess the right number.

Below is the flowchart for this game designed to be implemented with a high level programming language such as Visual Basic. Note that if this flowchart was to be implemented in Python it would have to be changed slightly to replace the repeat until loop with a while loop as there is no repeat until loop in Python.
guess-the-number-flowchart-repeat-until

Little Man Computer


Your challenge is to redesign this algorithm for a low level assembly language (See LMC instruction set below). You will then be able to code this game using one of the following online LMC Simulators:

Note that these LMC similators only manipulate numbers so you will have to use the following values for your output messages:

  • “Higher!” will output number 1
  • “Lower!” will output number 0
  • “You win!” will output number 9

LMC Instruction Set


Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.

Mnemonic Name Description Op Code
INP INPUT Retrieve user input and stores it in the accumulator. 901
OUT OUTPUT Output the value stored in the accumulator. 902
LDA LOAD Load the Accumulator with the contents of the memory address given. 5xx
STA STORE Store the value in the Accumulator in the memory address given. 3xx
ADD ADD Add the contents of the memory address to the Accumulator 1xx
SUB SUBTRACT Subtract the contents of the memory address from the Accumulator 2xx
BRP BRANCH IF POSITIVE Branch/Jump to the address given if the Accumulator is zero or positive. 8xx
BRZ BRANCH IF ZERO Branch/Jump to the address given if the Accumulator is zero. 7xx
BRA BRANCH ALWAYS Branch/Jump to the address given. 6xx
HLT HALT Stop the code 000
DAT DATA LOCATION Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.
unlock-access

Solution...

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

Network Design

In this post we will investigate the different components needed to set up a network. We will investigate their purpose and how all the devices are connected together to create a basic network diagram/design.

Your task will then to design the network diagram for your school or organisation.

LAN & WANNetwork TopologiesNetwork ComponentsClient Server NetworksVPNDesign Your Own Network

LAN vs WAN


A LAN (Local Area Network) is a network located on one site, where all the computers are geographically close to each others.

A WAN (Wide Area Network) is a network that is spread across multiple sites sometimes geographically remote to one another. A WAN consists of several LANs connected together, often using third party equipment and cables. (e.g. BT lines in the UK or AT&T lines in the US)

The Internet is an example of WAN (the largest of all WANs!).

A router is needed to connect a LAN to a WAN (or to the Internet).
LAN-Router-WAN

Star Topology

A network topology defines the layout of a network. It describes how different components/nodes of a network are connected together. One of the most frequent topology used in a LAN is the star topology where all computers and other devices are all connected to a central node: either a hub or a switch.Star-Topology-HubBoth a hub or a switch have the same purposes: to connect multiple computers or devices in a star topology. A hub is not as efficient as a switch and would often have less ethernet ports (e.g. typically 4 or 8 ports)Star-Topology-SwitchA switch being more efficient than a hub could have a larger number of devices connected (e.g. up to 28 Ethernet ports).

Switch-Star Topology

To build a larger network, it is possible to combine multiple star networks using a central switch. This creates a “switch-star” topology:
switch-star-topology

Other Topologies


Note that there are other types of topologies which are not based on the star topology. (e.g. bus topology, ring topology, full and partial mesh topologies).

Full Mesh Topology

Full Mesh Topology

Partial Mesh Topology

Partial Mesh Topology

However, for now, we will focus on star based topologies as these are the most frequently used topologies to build a LAN for a school or a small business.

Network Components (Hardware)

At this stage, we have already looked at three of the main types of network components: router, hub and switch. Other devices can also be used on a network such as a Wireless Access Point (WAP) and a Firewall.

Router

A router is needed to connect a LAN to a WAN (or to the Internet). A router scans data packets and redirects them towards the LAN or towards other routers depending on their origin and their destination.
LAN-Router-WAN

Switches and Hubs
A switch is a network component used to connect multiple devices together in a star topology. A switch would have a number of Ethernet ports (typically between 8 and 28 ports) to connect to other devices such as workstations and servers, WAPs, other hubs or switches or to a firewall or a router.
Star-Topology-SwitchA switch is more efficient than a hub as it can redirect traffic towards the device it is aimed at. Switches can hence be used on larger networks where hubs would be inefficient. (e.g. school network, hospital network, etc).

A hub is a network component used to connect multiple devices together in a star topology. A hub would have a number of Ethernet ports (typically between 5 and 8 ports) to connect to other devices such as workstations and servers, WAPs, other hubs or switches or to a firewall or a router.Star-Topology-Hub
A hub is not as efficient as a switch and hence should only be used on a small network. (e.g. home network).

Wireless Access Point (WAP)

A Wireless Access Point (WAP) is a network component used to connect multiple devices together without using wires. A WAP could hence be described as being a wireless hub! It provides WiFi access to a network.

Most WAPs have a fairly small coverage area (10 to 30 meters) hence several WAPs may be required to cover a large building.
wireless-access-point-WAP
Devices equipped with a wireless Network Interface Card (NIC) can connect to a WAP.

Wireless data can easily be intercepted by potential hackers hence the need to encrypt wireless transmissions and to set a network key to restrict access to a wireless network (WiFi).

Firewall

A firewall is a network component that usually “sits” just after the main router. It scans all incoming traffic to identify/block and report potential security threats coming from “outside” (e.g. the Internet) before they can reach the rest of the Local Area Network. A firewall is a necessary precaution to minimise the risk of hackers illegally accessing a network.
network-firewall

NIC Cards

To connect a workstation to a LAN, the workstation needs to be equipped with a Network Interface Card (NIC). The NIC card will have a wired connection (e.g. Ethernet port) and/or a wireless connection to connect wirelessly to a WAP (Wireless Access Point).

Ethernet Cables

Networking cables are used to connect one network device to other network devices or to connect two or more computers to share printers, scanners etc.

The most widely used network cables are Ethernet Cables of different categories (Cat3, Cat5, Cat6, etc). These are fairly cheap, strong and can support a bandwidth of either 10 Mbps, 100 Mbps, 1000 Mbps (1 Gbps) or even 10Gbps.

Other types of cables that can be used on a network include coaxial cables (10 Mbps) and optic fibre cables (10 Gbps).

Did you know?

On a home network, a router is often an “all in one” device which includes a router, a hub or a switch, a Wireless Access Point (WAP) and a firewall, all in one box called router (or home hub).

A computer on a network is called a workstation. Two types of network can be setup.

  • Peer-to-peer networks
  • Client-server networks
Peer-to-peer networks

In a peer-to-peer network, all computers are sharing files and other resources between each other without the use of a central server. This makes it easy to setup the network as there is no need to acquire and setup expensive servers. However, this can be difficult to manage as maintenance and computer upgrades (including security patches, virus protection) have to be performed on each single computer instead of being done centrally. This is the main reason why peer-to-peer networks are considered as less secure than client-server networks.

Client-Server networks

In a client-server network, end-users access the network by logging on a client computer/workstation. Other computers called servers (often with higher specifications) are also connected to the network and provide a dedicated and centralised service to all the workstations. There are different types of servers as described below. On a small network, a single server can have multiple purposes (e.g. web server and e-mail server or a proxy and a cache server)

File server
A server with large storage capacity used to store all the files from all the network users as well as from shared network areas.
E-Mail server
A server that manages all e-mail accounts and transfers (sending/receiving) of e-mails for all network users.
Backup server
A server with large storage capacity used to store backups (copies) of files and data from other servers/workstations. Should the live data be corrupted or deleted, backed up data can be recovered from the backup server.
Print server
A server that manage all print requests from network users, manage print queues and end-user print credits.
Application server
A server that has all the applications and software upgrades files so that they can be centrally managed and centrally applied to all workstations that connect to the applications server to receive and install the latest upgrades when relevant. On occasion applications can also run directly from an application server, reducing the need to install these on each workstation of the network.
Multimedia server
A server with large storage capacity used to store all multimedia content (video clips, audio files, etc.).
Web server
A server used to host a website or internal webpages. The server contains all the necessary files (web pages, graphics, etc.) and processes all web requests from web users.
Cache server
A server that temporary stores recently accessed data/files so that they can be retrieved from the cache server at a faster rate.
Proxy server
A proxy server functions as an intermediary between a client and a server.

It can be used to monitor access to the Internet and apply necessary restrictions and filters to allow or block access to specific websites (e.g. educational filters).

DNS server
A server on the Internet used to lookup domain names to retrieve their matching IP addresses. These are necessary as end-users prefer to type web addresses or e-mail addresses using domain names such as www.101computing.net as these are easier to remember than IP addresses. The domain name servers will convert/lookup such domain names to find their matching IP addresses needed to connect to the relevant servers.
On occasions, a company may need its employees to access its network remotely (e.g. for employees working from home or on a business trip).

To do so, employees will connect to the company LAN using their own Internet connection. They will then authenticate to access to the company network as if they were on site and hence have access to the company’s private network.

network-design-virtual-private-network-vpn

To enable remote access to its network via the Internet, which is a public network, the company has to set up and configure a VPN (Virtual Private Network). This will also mean that all the communications between the remote user and the company network will have to be encrypted and the remote users will have to authenticate (e.g. enter their username and password) to gain access to the VPN, so that only authorised users can do so.

Design Your Own Network


Use our network designer tool to create the layout of the network used in your school/organisation:
LAN-Network-Design
Design Your Own Network Online
Tagged with:

Code breaking using Trace Tables

In the following set of challenges, you will use a trace table to workout the secret code of the following six padlocks. Before attempting this challenge, you may want to find out mode about the use of trace tables when testing or predicting the output of an algorithm.

Padlock #1Padlock #2Padlock #3Padlock #4Padlock #5Padlock #6

Padlock #1:


The following code will help you work out the combination (code) to open padlock #1 (see below)

code = ""
FOR i FROM 1 TO 3
   digit = i * 2
   code = code + STR(digit)
NEXT i
OUTPUT(code)

Trace Table

 Line NumberidigitcodeOUTPUT
1“”
21
32
4“2”
22
34
4“24”
23
36
4“246”
6246

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

Padlock #2:


The following code will help you work out the combination (code) to open padlock #2 (see below)

code = ""
code = code + "9" 
code = code + "7"
code = code + "1"
OUTPUT(code)

Trace Table


Complete the following trace table to work out the 3-digit padlock code:
 Line NumbercodeOUTPUT
1

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

Padlock #3:


The following code will help you work out the combination (code) to open padlock #3 (see below)

code = ""
code = code + "7" 
code = "4" + code
code = code + "3"
OUTPUT(code)

Trace Table


Complete the following trace table to work out the 3-digit padlock code:
 Line NumbercodeOUTPUT
1

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

Padlock #4:


The following code will help you work out the combination (code) to open padlock #4 (see below)

code = 61 
IF code MOD 2 == 0 THEN
   code = code * 3
ELSE
   code = code * 2
END IF
OUTPUT(code)

Trace Table


Complete the following trace table to work out the 3-digit padlock code:
 Line Numbercodecode MOD 2 == 0 ?OUTPUT
1

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

Padlock #5:


The following code will help you work out the combination (code) to open padlock #5 (see below)

code = 24 
IF code > 20 AND code <= 10 THEN
   code = code * 3
ELSE IF code > 20 OR code <= 10 THEN 
   code = code * 10
ELSE 
   code = code * 4
END IF
OUTPUT(code)

Trace Table


Complete the following trace table to work out the 3-digit padlock code:
 Line Numbercodecode>20 ?code<=10 ?OUTPUT
1

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

Padlock #6:


The following code will help you work out the combination (code) to open padlock #6 (see below)

code = 245 
WHILE code < 1000
   code = code + 200
END WHILE
code = code - 200
OUTPUT(code)

Trace Table


Complete the following trace table to work out the 3-digit padlock code:
 Line Numbercodecode<1000 ?OUTPUT
1

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

Using Trace Tables

A trace table is a technique used to test an algorithm and predict step by step how the computer will run the algorithm. It can be used to understand or predict what an algorithm is doing and to identify potential logic errors (when the program compiles but does not produce the expected output).

The animation below demonstrate the use of a trace table used to track the values of variables as they change while the program is running. trace-table-s

Using a trace table to test an algorithm is called dry run testing.

Your Task


Check the following algorithms and complete their trace tables. (Click on any cells of these tables to add content)
Algorithm #1Algorithm #2Algorithm #3Algorithm #4

Algorithm #1: While Loop

i = 0
j = 10

WHILE i < j
   i = i + 1
   j = j - 1
END WHILE

OUTPUT(i)
OUTPUT(j)

Trace Table

 Line Numberiji < jOUTPUT
10
210
4True
51
69
4True

Algorithm #2: Factorial

number = 5
factorial = number

WHILE number>2
   number = number - 1
   factorial = factorial * number
END WHILE

OUTPUT(factorial)

Trace Table

 Line Numbernumberfactorialnumber > 2OUTPUT
15
25

Algorithm #3: Fizz-Buzz Sequence

FOR i FROM 1 TO 20
   IF i MOD 3 == 0 AND i MOD 5 == 0 THEN
      OUTPUT "Fizz-Buzz"
   ELSE IF i MOD 3 == 0 THEN
      OUTPUT "Fizz"
   ELSE IF i MOD 5 == 0 THEN
      OUTPUT "Buzz"
   ELSE
      OUTPUT i
   END IF
NEXT i

OUTPUT("The End")

Trace Table

 Line Numberii MOD 3 == 0i MOD 5 == 0OUTPUT
11
2FalseFalse
4False
6False
8
91
12

Algorithm #4: Max Function

FUNCTION max(a, b)
   IF a>b THEN
      RETURN a
   ELSE 
      RETURN b
   END IF
END FUNCTION

number1 = 7
number2 = 12
number3 = max(number1, number2)
OUTPUT(number3)

Trace Table

 Line Numbernumber1number2number3aba>bRETURNOUTPUT
97
1012
11712
1712