More results...

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

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?

Secret Code

In this challenge we are putting your deciphering skills to the test.

Here are your secret codes. Will you be able to decode these?

Cipher #1

0101010001101000011001010010000001000001010100110100001101001001010010010010000001100011011011110110010001100101001000000110100101110011001000000111010101110011011001010110010000100000011101000110111100100000011000110110111101101110011101100110010101110010011101000010000001110100011001010111100001110100001000000111010001101111001000000110001001101001011011100110000101110010011110010010000001100011011011110110010001100101001000010010000001010100011010000110010100100000010000010101001101000011010010010100100100100000011000110110111101100100011001010010000001100011011011110110111001110100011000010110100101101110011100110010000000110001001100100011100000100000011000110110100001100001011100100110000101100011011101000110010101110010011100110010111000100000010101000110100001100101001000000110010101111000011101000110010101101110011001000110010101100100001000000100000101010011010000110100100101001001001000000110001101101111011001000110010100100000011000110110111101101110011101000110000101101001011011100111001100100000001100100011010100110110001000000110001101101000011000010111001001100001011000110111010001100101011100100111001100101110

Cipher #2

\u0055\u006e\u0069\u0063\u006f\u0064\u0065 \u0069\u0073 \u0061 \u0063\u0068\u0061\u0072\u0061\u0063\u0074\u0065\u0072 \u0073\u0065\u0074 \u0075\u0073\u0069\u006e\u0067 \u0032 \u0042\u0079\u0074\u0065\u0073 \u0070\u0065\u0072 \u0063\u0068\u0061\u0072\u0061\u0063\u0074\u0065\u0072 \u0077\u0068\u0069\u0063\u0068 \u006d\u0065\u0061\u006e\u0073 \u0069\u0074 \u0063\u0061\u006e \u0072\u0065\u0070\u0072\u0065\u0073\u0065\u006e\u0074 \u006d\u006f\u0072\u0065 \u0074\u0068\u0061\u006e \u0036\u0035\u002c\u0030\u0030\u0030 \u0075\u006e\u0069\u0071\u0075\u0065 \u0063\u0068\u0061\u0072\u0061\u0063\u0074\u0065\u0072\u0073\u002e \u0054\u0068\u0069\u0073 \u0069\u0073 \u0077\u0068\u0079 \u0075\u006e\u0069\u0063\u006f\u0064\u0065 \u0069\u0073 \u0075\u0073\u0065\u0064 \u0074\u006f \u0065\u006e\u0063\u006f\u0064\u0065 \u004a\u0061\u0070\u0061\u006e\u0065\u0073\u0065 \u0063\u0068\u0061\u0072\u0061\u0063\u0074\u0065\u0072\u0073 \u0028\u0065\u002e\u0067 \u6628\u002c\u591c\u002c \u6700\u002c\u9ad8\u0029 \u006f\u0072 \u0041\u0072\u0061\u0062\u0069\u0063 \u0063\u0068\u0061\u0072\u0061\u0063\u0074\u0065\u0072\u0073 \u0028\u0065\u002e\u0067\u002e \u0635 \u002c\u0639 \u0634 \u002c\u062c\u0029\u002e
Tagged with: , , ,

Data Types Quiz

When using variables and constants in your programs it is important to use the correct data types.

The main data types are:

  • Integer: for whole numbers only such as 7,
  • Float/Real: for numbers with decimals only such as 9.81,
  • String: for piece of text. It can also include number digits and punctuation signs. e.g. “IP4 5HD”, “Hello world!”,
  • Boolean: for values which are either True or False,
  • Date & Time: for dates! (With or without a time): e.g. 31/12/2015 00:00:00, 25/12/2015

Test your knowledge of Data Types (open full screen):


Tagged with:

Haunted House

haunted-houseYou are going to write a Python game where the user walks within the different rooms of a haunted house.

In each room, something will happen. You will decide what happens when the user enters a room. You can use some of the following ideas:

  • Maybe a ghost will appear (ASCII Art using the print command) when the user enters the bedroom,
  • You could have three magic potions on the kitchen table and your program could ask the user to choose one of them. It would then display a different message based on the potion chosen by the user,
  • There could be a secret passage in the library to lead to the kitchen,
  • There could be a random math question to solve in the living room, and if the user does not give the correct answer they lose.

Designing the game


Open and print the following floor plan. Write in each room what you would like your program to do when the user enters the room.

hauntedhouse

Let’s get coding


We have started the game for you with some (but not all) the options for the user to walk from one room to the other.

Complete this game, one room at a time:

Code for the library() function

Here is an example of code for the library() function. Looking at the floor plan of the mansion, you will notice that there is only one door to go back to the hall. However we are going to add a secret passage to lead to the kitchen.

def library():
  print("--- You are entering the library ---")
  print("")
  time.sleep(1)
  print("While looking at the books on the bookshelves, you notice that one of the book is not perfectly aligned with the other books.")
  print("""
                       ┌─┐
   ┌─┐  ┌─┐   ┌──┐     │ │
┌──┤ │  │ ├───┤  ├─────┤ │
│  │ ├──┤ │   ├──┤     │ ├───┐
│  ├─┤xx│ │   │┼┼│ ─── │ │   │
│  ├─┤  │ ├───┼──┤     │ │ ┌─┤
│  │ │  │ ├───┤  │ ─── │ │ └─┤
│  │ │  │ │   │  │     │ │   │
│  │ │  │ │   │  │     │ │   │
└──┴─┴──┴─┴───┤  ├─────┴─┴───┘
              └──┘
  """)
  time.sleep(1)
  option = input("Do you: \n a) pick up this book \n b) Leave this book where it is and go back to the hall").lower()
  if option == "a":
      print("When trying to pick up the book, the book acts as a lever and the bookshelf slides to the left revealing a secret passage.")
      time.sleep(1)
      print("Feeling adventurous, you decide to go through this secret passage and realise that it leads you to the kitchen.")
      time.sleep(1)
      kitchen()
  elif option == "b":
      print("Hum... I do wonder why this book was not perfectly aligned? Anyway, let's go back to the hall...")
      time.sleep(2)
      hall()

Note that for this code to work, you will also need to define a new function for the kitchen:

def kitchen():
  print("--- You are entering the kitchen ---")
  print("")
  time.sleep(1)
  #complete the code here

Using an inventory

We will now add an inventory to our code to let the player collect objects as they progress through the game. To do so we will first initialise a new empty list called inventory using the following line of code that we will place at the very beginning of our code (e.g. on line 3)

inventory = []

Then we will add some code to our kitchen() function for the player to pick up a golden key.
In Python, we can check if a value is in a list using the keyword in.
For instance we will only display the key on the floor of the kitchen, if the user has not already picked it up using the following line of code:

if "Golden Key" not in inventory:

To add a value to a list we will use the append() function as follows:

inventory.append("Golden Key")

Let’s use this code to let the user pick up the key from the kitchen floor.

def kitchen():
  print("--- You are entering the kitchen ---")
  print("")
  time.sleep(1)
  
  if "Golden Key" not in inventory:
    print("""
         ┌──────┐
         │      │
         │      ├────────┬─┬──┬─┐
         │      │        │ ├──┤ │
         └──────┘        └─┘  └─┘
    """)
    print("As you enter into the kitchen, you notice a golden key on the floor and decide to pick it up as it could become useful later on.")
    inventory.append("Golden Key")
    print("Inventory:")
    print(inventory)
    #Add code here to decide where to go next

Then, in other rooms, you will be able to check if the user has the key to for instance let them open a treasure chest.

def bedroom():
  print("--- You are entering bedroom ---")
  print("")
  time.sleep(1)
  print("Hidden under the bed, you find a treasure chest.")
  if "Golden Key" in inventory:
     print("You use your golden key to open it and found a silver crown inside it.")
     inventory.append("Silver Crown")
     print("Inventory:")
     print(inventory)
  else:
     print("The treasure chest is locked and you do not seem to have the key to unlock it!")
  #Add code here to decide where to go next
 
Tagged with: , , ,