More results...

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

Understanding Abstraction

In computer science, abstraction is a technique for managing complexity of computer systems. It works by establishing a level of complexity on which a person interacts with the system, suppressing the more complex details below the current level.

In order to create complex computer system, computer scientists have to look at the big picture first to clearly identify the problem they want to solve and progressively elaborate a solution to solve this problem. This is the concept of abstraction, which can be broken down in a few set of steps. Each step enables computer scientists to add more details on how they will solve their problem.

Abstraction Step 1: Problem Definition:


It is essential to clearly identify the problem that we want to solve. To do so it is essential to understand the needs of the end-user and the difference between computerised models and the reality.

abstraction-step-1

For this blog post, we are going to focus on the following problem:
How can we create a computer program used in the Google car to inform the passengers on the directions for their journey as well as to provide them with factual information such as estimated mileage and duration of their journey?

Abstraction Step 2: Identify the inputs and outputs of our solution:

abstraction-step-2

In our scenario we have the following inputs and outputs:

abstraction-step-2b

Abstraction Step 3: Identify the main components of our problem:


In our scenario we have identified four main components as follows:

abstraction-step-3

Abstraction Step 4: Identify potential for code reusability by:


  • Using existing libraries,

  • Defining functions and procedures,

  • Using Object Oriented concepts such as the use of Classes and objects.

abstraction-step-4

Abstraction Step 5: Design the programming algorithms:


Design the algorithms for every element of the solution. These algorithms will be based on the key procedural programming concepts: Sequencing, Selection and Iteration.
These algorithms will also rely on the use of variables and appropriate data structures.

abstraction-step-5

Tagged with:

The Collatz Conjecture

The Collatz conjecture is a famous mathematical mystery that has yet to be solved. It is named after Lothar Collatz a German mathematician, who first proposed it in 1937.

It is based on the following number sequence:

  • Start with any positive whole number called n,
  • if n is even, divide it by 2: n’ = n / 2,
  • if n is odd, multiply it by 3 and add 1: n’ = 3 x n + 1,
  • if n’ = 1 then stop the number sequence,
  • otherwise repeat this process with n’ as your starting number.

Let’s see how this number sequence behaves with some of the following numbers:

Collatz-Conjoncture
These number sequences are known as hailstone sequences because they go up and down just like a hailstone in a cloud before crashing to Earth.

It seems that these sequences always end up reaching an endless cycle: The endless cycle being 4, 2 , 1. (If we carry on, 1 being odd becomes 3 x 1 + 1 = 4).

Collatz-Conjoncture-endless-cycle

An unsolved problem:


The question that these sequences are raising is: Does such number sequences always settle on the 4,2,1 cycle no matter what starting value we use? It is conjectured (but not yet proven) that they will, in other words that each hailstone sequence will always terminate at n = 1.

Experiments certainly suggest that it does. Computers have checked all starting values up to 5 x 260, a number that is 19 digits long, and found that the 4, 2, 1 cycle eventually appears. The trouble is that nobody has been able to prove that this is the case for all starting numbers!

This unsolved mathematical question/unproven conjecture is known as the Collatz conjecture.

Your Challenge


Write a computer program that will implement a hailstone number sequence. Ask the user to input the starting number and display all the numbers generated by the number sequence till you reach the value of 1. Make sure that your number sequence follow the rules listed at the beginning of this blog post.

Extension Task:


Did you use iteration (for instance a while loop) to complete this challenge?

If so do some research about how recursion works. Change your code to swap your loop for a recursive approach.

unlock-access

Solution...

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

Merry Christmas

merry-christmasFor this challenge we are going to create Christmas Cards using Python turtle.

We will use the random library to create unique cards.

Starry Night


Our first card consists of creating a starry night scene.

This card is using:

  1. A function called draw_star() that takes five parameters: myPen, colour code, x position, y position and size of the star,
  2. Iteration: A for loop to create 15 stars,
  3. x and y coordinates to position the stars on the canvas,
  4. The random library, using the randint() function to randomly position the stars on the canvas.

(X,Y) Coordinates


The canvas we are drawing on (using Python Turtle) is 400 pixels wide by 400 pixels high.
Look at the canvas below to understand how (x,y) coordinates work:

Christmas Tree


Our second card consists of creating a Christmas Tree.

This card is using:

  1. A function called draw_rectangle() that takes six parameters: myPen, colour code, x position, y position, width and height of the rectangle,
  2. Iteration: A while loop to add more layers to the tree till we reach a thin enough top layer,
  3. x and y coordinates to position the rectangles on the canvas,
  4. The random library, using the randint() function to randomly set the width and height the rectangles on the canvas.

Tweak this card:
What’s about adding 20 snowflakes behind this tree, using the draw_circle() function.
Make sure the snowflakes are randomly positioned on the canvas.

Your Challenge


Your challenge consists of creating one of the following three Christmas cards:
xmas-cards

Make sure that your code uses:

  1. The randint() function from the random library to make sure each snowman, tree or hat is unique,
  2. A loop to reduce the number of instructions in 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: , ,

Sequencing, Selection & Iteration

When you write lines of code, there are three ways you can control the order these lines will be executed by the computer:

  1. Sequencing: This means that the computer will run your code in order, one line at a time from the top to the bottom of your program. It will start at line 1, then execute line 2 then line 3 and so on till it reaches the last line of your program.
  2. Selection: Sometimes you only want some lines of code to be run only if a condition is met, otherwise you want the computer to ignore these lines and jump over them. This is achieved using IF statements. e.g. If a condition is met then lines 4, 5, 6 are executed otherwise the computer jumps to line 7 without even looking at line 4,5 and 6.
  3. Iteration: Sometimes you want the computer to execute the same lines of code several times. This is done using a loop. There are three types of loops: For loops, while loops and repeat until loops. That’s handy as it enables you not to have to copy the same lines of code many times.

Take the quiz (open full screen):


Tagged with: , , ,

Vector Based Graphics

Computers can use two types of graphics:

  • Bitmaps: A bitmap (or raster graphic) is a digital image composed of a matrix of dots. When viewed at 100%, each dot corresponds to an individual pixel on a display. In a standard bitmap image, each dot can be assigned a different colour.
  • Vector-based graphics: Unlike bitmap graphics, vector graphics are not made up of a grid of pixels. Instead, vector graphics are made of mathematical/geometric instructions known as “paths”. A path can be a line, a square, a triangle, or a curvy shape. A path is defined by a start and an end point, along with other points, curves, and angles along the way. These paths can be used to create simple drawings or complex diagrams.

The purpose of this blog post is to demonstrate what vector based graphics consist of and how they are stored on the computer.

SVG is a format used to create vector based graphics.

See the codepen below to see how the following graphic is created using SVG code. Click on “Edit on CODEPEN” to tweak this code and change this graphic.

See the Pen Vector Based Graphic by 101 Computing (@101Computing) on CodePen.

Check this page from w3schools.com to learn about SVG graphics that can be used directly into an HTML5 page.

Your Challenge


Pick any graphic from the Christmas collection or from the Science collection below and try to recreate this graphic using SVG code (by editing the above CodePen).

Christmas Collection
xmas-graphics

Science Collection
science-graphics

Tagged with: , , , ,

Computing Operators

While programming with high-level languages such as Python, you will use four different types of operators as follows:

  • The assignment operator ( = ) which is used to assign a value to a variable or a constant.
  • Arithmetic operators ( +, -, *, / ) which are used to perform mathematical calculations.
  • Comparison operators ( >, <, >=, <=, ==, != ) which are used to compare values.
  • Boolean operators ( AND, OR, NOT ) which are often used to complete more than one comparison.

Match the dominoes!


Click on the picture below to start:
operators-dominoes

Tagged with: , , , ,

Beach Huts Challenge

beach-hutsLook at the code below to draw lines of beach huts.

(X,Y) Coordinates


The canvas we are drawing on (using Python Turtle) is 400 pixels wide by 400 pixels high.
Look at the canvas below to understand how (x,y) coordinates work:

Python Code

Your task is to tweak the code used to draw the third line of beach huts. On this line we want the computer to choose random colours from the colour list – that’s already the case! However this time we want to make sure that we cannot have two beach huts of the same colour next to each other.


unlock-access

Solution...

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

Operators Quiz

While programming with high-level languages such as Python, you will use four different types of operators as follows:

  • The assignment operator ( = ) which is used to assign a value to a variable or a constant.
  • Arithmetic operators ( +, -, *, / ) which are used to perform mathematical calculations.
  • Comparison operators ( >, <, >=, <=, ==, != ) which are used to compare values.
  • Boolean operators ( AND, OR, NOT ) which are often used to complete more than one comparison.

Take the Quiz! (open full screen)

Guess the country

globeFor this challenge we are going to create a game where the user plays against the computer.

The aim of this game is to guess the name of a country. The computer will give the player clues to help them identify the country. The aim for the player is to try to guess the country using as few clues as possible.

For this challenge we are going to work from a flowchart that describes the algorithm we will base our code on: (Click on the picture to zoom in)

GuessTheCountry

Let’s get coding


We have started the code for you. Use the flowchart above to complete this code.

Extension task #1


Could you tweak this code to display at the end how many clues have been used in total to guess the country.

Extension task #2


This code only works with one country.

How could we change it to have a list countries and a list of clues for each country and get the computer to randomly choose one country from the list of countries.

Tip: To solve this task you may want to investigate how to use a list of lists in Python.

Tagged with: , ,

Question Time

Feeling confident with your computing knowledge?

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


?
Why are there around 16 milion colours in the RGB colour palette?


?
Why would a text file containing 3,000 characters use around 3 kilobytes?


?
Why are there 1024 (and not 1000) bits in a kilobyte?


?
Why do we use RGB colour codes when the three primary colours are Red, Yellow and Blue.


?
What is the expression:
= != ==
telling us?


?
Is the boolean expression:
(NOT A) AND (NOT B)
the equivalent of
NOT (A OR B)

?


?
How can we tell that #333333 is a darker grey colour than #AAAAAA?


?
How can we tell that #FF00FF is a magenta/purple colour?


?
Why do we store phone numbers or credit card numbers as strings and not integers?


?
Why do bitmap pictures pixelate when they are resized/enlarged but vector-based pictures don’t?


?
What is the maximum number of devices that we can connect on the Internet at the same time (using IPv4)?


?
Does it take longer to download a file from a sever located in Australia or in Europe?


?
How does internet data cross the Atlantic Ocean?


?
How does Google search the entire web in just a few milliseconds?


?
Would it be possible for a computer to have a sense of humour?