More results...

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

Scratch -Take the Quiz!

Answer these 10 questions to test your understanding of Block Programming when using Scratch.

Take the Quiz! (open full screen)


Check that you understand the different types of validation checks by completing this quiz:

Extension Task


Use the scratch website to recreate some of the scripts used in this quiz.

Tagged with: , ,

Flowchart Prediction Tables

For each of the following flowcharts complete the matching prediction table to work out the expected output based on the given input values.

Flowchart #1Flowchart #2Flowchart #3
flowchart-guess-the-output-1

Input Values Expected Output
X Y
10 15
8 6
16 12
10 5
Check my answers!
flowchart-guess-the-output-2

Input Values Expected Output
X Y
4 3
5 4
-5 3
0 10
Check my answers!
flowchart-guess-the-output-3

Input Values Expected Output
X Y
0 3
10 8
0 2
10 0
Check my answers!


unlock-access

Solution...

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

Computer Graphics Crossword

crosswordAre you confident with your understanding of computer graphics? Can you explain the difference between bitmap graphics and vector-based graphics?


Computer GraphicsOpen 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:

Bitmap vs. Vector Based Graphics

It’s almost impossible to discuss graphics software without first establishing an understanding of the differences between the two major graphic types: bitmap and vector images.

The following “fill in the blank” activities will test your understanding of the characteristics of both types of graphics.

Bitmap/Raster GraphicsVector Based Graphics

Bitmap/Raster Graphics


pixels
Raster
(0,0,0)
million
tiny dots
resolution
PNG
Green
digital
8 mega pixels
(0,185,185)
scanner
bitmap-pixelsBitmap images (also known as images) are made up of in a grid. Pixels are picture elements; of individual colour that make up what you see on your screen. Pixels are defined by 2 properties: their position on the picture/grid and their colour value. These properties are stored in a bitmap file for every single pixel in the picture.

The colour value of each pixel is determined by the RGB colour code. (Red Blue). Each colour is made of a mix of these 3 primary colours. Each of these 3 colour have a value between 0 and 256. Hence a bitmap can have up to 256* 256 * 256 = 16 possible shades.

Red: (255, 0, 0) Purple: (85,0,85)
Yellow: (255,255,0) White: (255,255,255)
Cyan: Black:

When you use a camera or a or a graphic tablet you create bitmap pictures.

Bitmap pictures come under different file extensions: BMP, GIF, JPEG, , TIFF.

The quality of a bitmap file is determined by its which tells you how many pixels the bitmap is made of. For instance a digital camera can have an resolution.


pixel-art-old-school
Pixel art graphics used in retro arcade games are a good example of bitmap pictures. You can create your own pixel art online using piskelapp.com

Vector Based Graphics


thickness
compressed
geometric shapes
processing
CAD drawings
grouped
pixelate
gallery
vector-based-graphic
Vector Based graphics (also known as object-orientated graphics) are made up of many individual . Each of these shapes can be defined by mathematical/geometric statements and has individual properties assigned to it such as colour, fill, and size, , ...

All these geometric based data is saved in a vector based graphics as instructions such as:
DrawLine Red, 1 pixel wide, 10 pixels long From position x=20 y=40

When editing a vector based graphics each object can be edited individually. Objects can also be to be moved/resized/rotated together.

Cliparts from the clipart tend to be vector based. are also vector based.

Vector based graphics do not loose quality or pixelate when they are resized as opposed to bitmap graphics which do or become blurry when they are enlarged or resized. Vector based cannot be as opposed to bitmap files which can be compressed (by loosing some quality)

Vector based files tend to take up less disk space than bitmaps. However Vector based graphics requires more power to be displayed on the screen.


pen-vectorCreate your own vector graphics online using vecteezy.com
Tagged with:

Data Validation Quiz

When programming a computer system, it is good practice to include a range of validation checks in the code to check if the data being inputted by the end-user follows some basic rules.

The aim of validation checks is to ensure that data used or stored by computer systems is valid. Invalid data may indeed make the system crash or may provide inaccurate information back to the user.

Validation checks cannot confirm if the data is correct or not but they can filter out a lot of invalid data.

There are different types of checks that can be implemented in your code such as:

  • Presence Check: When a field has to be filled in (mandatory field) and cannot be left blank/empty. (e.g username field when you sign in to a new system)
  • Length Check: When a field has to contain a set number of characters (e.g. a password is at least 8 characters long, a credit card number contains 16 digits).
  • Type Check: When a field has be of a certain data type (integer, float/real, etc.).
  • Range Check: When a field has be within a range, or greater or lower than given value. (e.g. A percentage value has to be between 0 and 100)
  • Lookup Check: When a field can only accept a certain set of values from a list (e.g. A title field can be either Mr, Mrs, Ms or Dr)
  • Character Check: When a field has to contain a specific character or type of characters. (e.g. An e-mail address should contain an “@” sign)

Take the Quiz! (open full screen)


Check that you understand the different types of validation checks by completing this quiz:

Tagged with:

Vera Molnár’s Artwork revisited using Python

vera-molnar-artworkVera Molnár (born 1924) is a French media artist of Hungarian origin. She is considered to be a pioneer of computer art. Trained as a traditional artist, she began working with computers in 1968, where she began to create algorithmic paintings based on simple geometric shapes and geometrical themes.

In this blog post we are looking at using Python Turtle to recreate some of her artwork. To create you own op art/computer art, you will need to be confident in using iterative algorithms and have a good understanding of Cartesian coordinates.

To find review some of Vera Molnár’s artwork you can use the following pages:

Artwork #1


This is our first attempt at recreating some of Vera Molnár’s artwork using Python Turtle.

Artwork #2


This is our second attempt at recreating some of Vera Molnár’s artwork using Python Turtle.

Your Task


Your task is to select on other piece of artwork from Vera Molnár and write a computer algorithm using Python Turtle to recreate it. You can do so by adapting the scripts provided above.

vera-molnar-computer-art

Find more work from Vera Molnár on Google Images

Tagged with: , , ,

Triangle Geometry Functions

In this challenge we will create a library of functions to apply the different formulas based on the geometry of triangles.

For each function, you will need to design the algorithm using either Pseudo-code or a flowchart, implement the function using the Python trinket provided below and use another algorithm to test your function.

PerimeterAreaAnglesEquilateralIsoscelesPythagoras' TheoremHeron's Formula
triangle-perimeter-formulaWrite a function called getPerimeter() that takes three parameters/arguments a, b, c (the length of each side of a triangle).

Your function should calculate and return the perimeter of this triangle.


Write an algorithm to test your function.
Your algorithm should:

  • Ask the user to enter the length of the 3 sides of a triangle,
  • Use the getPerimeter() function to retrieve the perimeter of the triangle,
  • Display the perimeter of the triangle
triangle-area-formulaWrite a function called getArea() that takes two parameters/arguments corresponding to the length of the base and of the height of a triangle.

Your function should calculate and return the area of this triangle.


Write an algorithm to test your function.
Your algorithm should:

  • Ask the user to enter the length of the base and height of a triangle,
  • Use the getArea() function to retrieve the area of the triangle,
  • Display the area of the triangle
triangle-angles-formulaWrite a function called getAngle() that takes two parameters/arguments called angle1 and angle2 (the value of two angles in degrees)

Your function should calculate and return the value of the third angle: (180 – angle1 – angle2)


Write an algorithm to test your function.
Your algorithm should:

  • Ask the user to enter the value of two angles in degrees,
  • Use the getAngle() function to retrieve the value of the third angle,
  • Display this value on screen.
triangle-equilateralWrite a function called isEquilateral() that takes three parameters a, b, c (the length of each side of a triangle).

Your function should workout if the triangle is equilateral (if all sides have the same length) and return a Boolean value (True or False) based on its finding.


Write an algorithm to test your function.
Your algorithm should:

  • Ask the user to enter the length of the 3 sides of a triangle,
  • Use the isEquilateral() function to find out if the triangle is an equilateral triangle,
  • Display a relevant message to the end user.
triangle-isoscelesWrite a function called isIsoscles() that takes three parameters a, b, c (the length of each side of a triangle).

Your function should workout if the triangle is an isosceles triangle (if any two sides have the same length) and return a Boolean value (True or False) based on its finding.


Write an algorithm to test your function.
Your algorithm should:

  • Ask the user to enter the length of the 3 sides of a triangle,
  • Use the isIsoscles() function to find out if the triangle is an isosceles triangle,
  • Display a relevant message to the end user.
triangle-pythagorasWrite a function called getHypotenuse() that takes two parameters/arguments called a and b (the length of two sides of a right-angled triangle).

Your function should calculate and return the length of the third side (the hypotenuse) of the triangle knowing that:
triangle-pythagoras-formula


Write an algorithm to test your function. Your algorithm should:

  • Ask the user to enter the length of the 2 sides of a right-angled triangle,
  • Use the getyHypotenuse() function to retrieve the value of the hypotenuse of the right–angled triangle,
  • Display the value of the Hypotenuse.

Write a function called isRightAngledTriangle(), that takes three parameters a, b and c and works out if the triangle is a right-angled triangle or not. Your function should return a Boolean value (True or False) based on its finding.


Write an algorithm to test your function. Your algorithm should:

  • Ask the user to enter the length of the 3 sides of a triangle,
  • Use the isRightAngledTriangle() function to find out if the triangle is a right-angled trinagle,
  • Display a relevant message to the end-user.
heron-formula
Write a function called getTriangleArea() that takes three parameters/arguments a, b, c (the length of each side of a triangle).

Your function will apply Heron’s formula to calculate and return the area of the triangle.


Write an algorithm to test your function.
Your algorithm should:

  • Ask the user to enter the length of the 3 sides of a triangle,
  • Use the getTriangleArea() function to retrieve the area of the triangle,
  • Display the area of the triangle

Python Code


We have already started the code for you and have completed the function getPerimeter() followed by a short algorithm to test this function.

Your task is to complete this Python script to create and test all the functions mentioned above.

unlock-access

Solution...

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

Heron’s Formula

The Heron’s formula is a famous formula used to calculate the area of a triangle based on the length of its three sides. It is called “Heron’s Formula” (sometimes called Hero’s formula) after Hero of Alexandria who was a Greek Engineer and Mathematician in 10 – 70 AD.

heron-formula

Python Task


Your task is to write a function called calculateTriangleArea(). Your function will:

  • Take three parameters corresponding to the length of the 3 sides of a triangle: a, b and c,
  • Apply Heron’s formula to calculate the area of the triangle,
  • Return the area of the triangle.

You will also then need to create a small program that will:

  • Ask the user to enter the length of the three sides of a triangle,
  • Calculate the area of the triangle using the calculateTriangleArea() function,
  • Output the area of the triangle.

Video Tutorial


Python Code


Test Plan:


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

Test # Input Values (in cm) Expected Output (in cm2) Pass/Fail?
#1 First side: 3
Second side: 4
Third side: 5
Area: 6
#2 First side: 8
Second side: 10
Third side: 12
Area: 39.686
#3 First side: 4
Second side: 8
Third side: 10
Area: 15.199

Extension Task #1


Create some extra functions to calculate the area of a square, of a rectangle and of a disc. Each function will need to accept the relevant parameters needed to calculate the area of the desired shape.

Extension Task #2


Create a menu system, where the user is asked what shapes they would like to calculate the area of before being asked to enter the relevant dimensions.

Did you know?


Illustration of Hero's Aeolipile (Steam Engine)

Illustration of Hero’s Aeolipile (Steam Engine)

Hero published a well-recognized description of a steam-powered device called an aeolipile (sometimes called a “Hero engine”). Among his most famous inventions was a windwheel, constituting the earliest instance of wind harnessing on land.

Tagged with:

Linear Search Functions

liear-search-algorithmFor this programming challenge we will investigate different functions which will all be based on a linear search algorithm.

Let’s consider a teacher who has decided to keep track of rewards issued to their students throughout the term by adding their name at the end of a text file each time they win a reward for their positive attitude and effort in lessons.

The teacher would like to write a few Python functions to:

  • scan the content of the text file and check if a particular students has received a reward or not,
  • count the number rewards a student has received throughout the term.
  • locate a student in the text file (identify the position/line number where the student’s name appear in the text file)

The teacher has started the code by creating a function called readTextFile() that takes a parameter called filename/ This function scan the context of the text file and return a list of all the names listed in the text file.

Using flowcharts, the teacher then worked out the algorithms for the extra functions they would like you to implement and test to complete the code. You can access these flowcharts below.

Is Listed?Rewards CountFind Position
The first function that you will need to implement is called isListed(), takes two parameters value and list and returns True if the value can be found in the list, false otherwise. To test this function you will need to implement the following algorithms:
flowchart-function-is-listed
Click on the above flowcharts to open in a new window

The third function is called count(), takes two parameters value and list and returns number of times the searched value appears in the list. To test this function you will need to implement the following algorithms used to count the number of rewards a student has received throughout the term.
flowchart-function-count
Click on the above flowcharts to open in a new window

The second function to implement is called findPosition() takes two parameters value and list and returns the position (starting at position 1) of the value in the list or -1 if the item is not found. To test this function you will need to implement the following algorithms used to locate a name in the text file by identifying the line number where such name appears in the file.
flowchart-function-find-position
Click on the above flowcharts to open in a new window

Python Code


You can now complete and test all three functions using the flowcharts provided above. The trinket below contains two tabs. In the second tab called “rewards.txt” you can access the content of the text file.

Alternative Approach


The Python syntax allows you to use loop through a list of values as follows:

for value in list:
   print(value)

Not all programming languages will let you use this syntax. An alternative approach is to use indices:

for i in range(0,len(list)):
   print(list[i])

In this case the flowchart for our count() function would become:
flowchart-count-function-length

unlock-access

Solution...

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

Leap Year Subroutine

calendar-iconA leap year is a calendar year that contains an additional day (29th of February) added to keep the calendar year synchronised with the astronomical year or seasonal year (which contains roughly 365¼ days or 365.242375 days to be more accurate).

An easy way to work out if a year is a leap year or not is to check if the year (e.g. 2020) is a multiple of 4. If it is, then it is most likely a leap year. Indeed, the rule is slightly more complex than this and can be summarised in three statements:

  • Leap years are any year that can be exactly divided by 4 (such as 2004, 2008, 2012, 2016, 2020, 2024, etc)
  • except if it can be exactly divided by 100, then it isn’t a leap year (such as 2100, 2200, etc)
  • except if it can be exactly divided by 400, then it is a leap year (such as 2000, 2400, 2800, etc)

In Python to work out if a number is a multiple of 4, we can calculate the remainder (MOD) of dividing this number by 4. If this remainder is equal to zero, then the number is a multiple of 4.

Based on this we can create a small function that will take a number (year) as a parameter and return whether the given year is a leap year or not. Here is the flowchart for this function called isLeapYear():
flowchart-leap-year

We can then this function in any program where we need to work out if a year is a leap year or not. For instance, we can create a program that:

  • Asks the user to enter a year (e.g. 2020)
  • Check if the year entered is a leap year or not (using our isLeapYear() function!)
  • Outputs a message to inform the user if the year is a leap year or not.

Here is the flowchart for this program:
isleapyear-flowchart

Video Tutorial


Your Task:


Use Python code to implement both the isLeapYear() function and the main program based on the above flowcharts.

Test Plan:


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

Test # Input Values Expected Output Pass/Fail?
#1 Year: 2020 2020 is a leap year.
It contains 366 days.
#2 Year: 2021 2021 is not a leap year.
It contains 365 days.
#3 Year: 2056 2056 is a leap year.
It contains 366 days.
#4 Year: 2100 2100 is a not a leap year.
It contains 365 days.
#5 Year: 2400 2400 is a leap year.
It contains 366 days.
unlock-access

Solution...

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