
Using a “scratch like” programming language you can create your own 3D models and export them in a format recognised by 3D Printers.
Click on the picture above to access the BeetleBlocks project:

Using a “scratch like” programming language you can create your own 3D models and export them in a format recognised by 3D Printers.
Click on the picture above to access the BeetleBlocks project:
Doctor Black has just been found dead in his bedroom. He has been knocked down by a heavy metallic object, most likely the candlestick that was found on the floor next to Doctor Black. When falling down, Doctor Black broke his watch which stopped at 8:14 PM. We can assume that this is the time of death.
Doctor Black’s bedroom is the master bedroom and is located on the first floor.
Our crime scene investigator took some notes to recap the key facts:

At this time of the day there were only four guests in Doctor Black’s mansion. They are the prime suspects:

Our crime scene investigator interviewed all four suspects and gathered some facts about their whereabouts around the time of death.
He has decided to create an algorithm based on these facts to help him solve this murder mystery. To do so he has translated each fact into pseudo code as follows:
Fact:
Pseudocode:
IF TimeOfMurder >= 6:00PM AND TimeOfMurder <= 8:00PM THEN
MissScarlett = "Innocent"
ProfessorPlum = "Innocent"
END IF

Below is our crime scene investigator’s full algorithm:
Will it help you solve this crime?
IF TimeOfMurder >= 6:00PM AND TimeOfMurder <= 8:00PM THEN
MissScarlett = "Innocent"
ProfessorPlum = "Innocent"
END IF
SELECT CASE LocationOfMurder:
CASE "1st Floor":
ReverendGreen = "Innocent"
CASE "Ground Level":
MissScarlett = "Innocent"
ColonelMustard = "Innocent"
CASE "Garden"
ProfessorPlum = "Innocent"
IF (MurderRoom == "Kitchen" OR MuderRoom == "Master Bedroom") AND timeOfMurder >= 8:00PM THEN
ProfessorPlum = "Innocent"
ELIF MurderRoom == "Bathroom" AND (timeOfMurder >= 8:00PM AND timeOfMurder <= 8:30PM) THEN
MissScarlett = "Guilty"
END IF
IF MurderWeapon == "Candlestick" OR MurderWeapon == "Rope" THEN
MurdererGender = "Male"
END IF
And the murderer is …

This tutorial is the second tutorial in a series of five Pygame tutorials:
Consider a sprite as an object. An object can have different properties (e.g. width, height, colour, etc.) and methods (e.g. jump(), hide(), moveForward(), etc.). Like in the industry an object is built from a mould. In computing the mould is called a Class.
So by creating our first sprite we will implement OOP (Object Orientated Programming). We will create our first Class and derive our first object from this class.
The main car will be an object called playerCar. It will derive from a Class called Car.
import pygame
WHITE = (255, 255, 255)
class Car(pygame.sprite.Sprite):
#This class represents a car. It derives from the "Sprite" class in Pygame.
def __init__(self, color, width, height):
# Call the parent class (Sprite) constructor
super().__init__()
# Pass in the color of the car, and its x and y position, width and height.
# Set the background color and set it to be transparent
self.image = pygame.Surface([width, height])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
# Draw the car (a rectangle!)
pygame.draw.rect(self.image, color, [0, 0, width, height])
# Instead we could load a proper pciture of a car...
# self.image = pygame.image.load("car.png").convert_alpha()
# Fetch the rectangle object that has the dimensions of the image.
self.rect = self.image.get_rect()
Later on we will add more properties and methods to this class. But before doing so we will look at how we can use it to create our first object: the car of the player (playerCar)
So let’s save our class as a python file called car.py.
Let’s go back to our main.py file (from previous tutorial) to edit its content.
First let’s add at the top of the code an import statement to import our Car class.
#Let's import the Car Class from car import Car
Then we need to create our sprite in our main program using the following line of code:
playerCar = Car(RED, 20, 30)
Per dafult your car will be on position (0,0) (top left og the screen). You can change the x and y properties of your car as follows:
playerCar.rect.x = 200 playerCar.rect.y = 300
You can see how easy it would be to create another car:
player1Car = Car(RED, 20, 30) player1Car.rect.x = 200 player1Car.rect.y = 300 player2Car = Car(PURPLE, 20, 30) player2Car.rect.x = 400 player2Car.rect.y = 400
However, fir now we do not need to add these two extra cars.
Let’s reuse the code from the first tutorial. We have made a few amendments since to draw the backdrop of our game: A green screen with a grey straight road!
On line 3 notice how we are using the import command to link to our Car Class python file (car.py).
On line 20 we are declaring a list called all_sprites_list that will store all the sprites we will create in our game. (For now just one sprite, the player car.)
On line 22 we are creating our first sprite/object using the Car Class. Notice how when declaring our first object we use the parameters from its constructor (__init__()), in this case, the colour, x, y, width and height of the car we want to create.
Now that we have created our first sprite we need to add it to our list of spites: all_sprites_list. This is what happens on line 27.
Finally, within the main program loop, on line 49 we are refreshing the screen and drawing all the sprites from our list: all_sprites_list.
Here is the full code:
import pygame, random
#Let's import the Car Class
from car import Car
pygame.init()
GREEN = (20, 255, 140)
GREY = (210, 210 ,210)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
PURPLE = (255, 0, 255)
SCREENWIDTH=400
SCREENHEIGHT=500
size = (SCREENWIDTH, SCREENHEIGHT)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Car Racing")
#This will be a list that will contain all the sprites we intend to use in our game.
all_sprites_list = pygame.sprite.Group()
playerCar = Car(RED, 20, 30)
playerCar.rect.x = 200
playerCar.rect.y = 300
# Add the car to the list of objects
all_sprites_list.add(playerCar)
#Allowing the user to close the window...
carryOn = True
clock=pygame.time.Clock()
while carryOn:
for event in pygame.event.get():
if event.type==pygame.QUIT:
carryOn=False
#Game Logic
all_sprites_list.update()
#Drawing on Screen
screen.fill(GREEN)
#Draw The Road
pygame.draw.rect(screen, GREY, [40,0, 200,300])
#Draw Line painting on the road
pygame.draw.line(screen, WHITE, [140,0],[140,300],5)
#Now let's draw all the sprites in one go. (For now we only have 1 sprite!)
all_sprites_list.draw(screen)
#Refresh Screen
pygame.display.flip()
#Number of frames per secong e.g. 60
clock.tick(60)
pygame.quit()
That’s it… You are now ready to move to our third tutorial to learn how to control your sprites using the arrow keys.
PyGame Tutorial 3/5Control your sprite using the arrow keys
For this challenge we are using a Raspberry Pi with Minecraft and Python 2 pre-installed.
Let’s see how this works…
Here is the Python code:
from mcpi import minecraft, block mc = minecraft.Minecraft.create() msg = "Hello Minecraft World from 101 Computing" mc.postToChat(msg)
So to test this program on your Raspberry Pi you will need to:
For this Python script we are going to write a function to teleport the player up in the sky. We will call this function “jump”. It will take one parameter: the distance (number of blocks) we want the player to jump (up in the sky).
To understand the code below we need to understand how (X,Y,Z) are used in minecraft to retrieve or change the position of a player (and later on the position of blocks).
from mcpi import minecraft, block
import time
def jump(distance):
#Let's wait 1 second
time.sleep(1)
#Retrieve the X,Y,Z coordinates of the player
pos=mc.player.getPos()
#Change the Y coordinate of the player to position it up in the sky
mc.player.setPos(pos.x, pos.y + distance, pos.z)
#Main Program Starts Here:
jump(100)
The purpose of this script is to build a ten-block high tower in front of the player. We will be using 3 different methods for you to compare:from mcpi import minecraft, block
import time
def createTower():
#Let's wait 1 second
time.sleep(1)
#Retrieve the X,Y,Z coordinates of the player
pos=mc.player.getPos()
#Create a 10-block high tower, 5 blocks away from the player
mc.setBlock(pos.x + 5, pos.y, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+1, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+2, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+3, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+4, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+5, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+6, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+7, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+8, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+9, pos.z, block.STONE)
mc.setBlock(pos.x + 5, pos.y+10, pos.z, block.STONE)
#Main Program Starts Here:
createTower()
from mcpi import minecraft, block
import time
def createTower(numberOfBlocks):
#Let's wait 1 second
time.sleep(1)
#Retrieve the X,Y,Z coordinates of the player
pos=mc.player.getPos()
#Create a tower 5 blocks away from the player
for i in range (0, numberOfBlocks):
mc.setBlock(pos.x + 5, pos.y + i, pos.z, block.STONE)
#Main Program Starts Here:
createTower(10)
from mcpi import minecraft, block
import time
def createTower(numberOfBlocks):
#Let's wait 1 second
time.sleep(1)
#Retrieve the X,Y,Z coordinates of the player
pos=mc.player.getPos()
#Create a tower 5 blocks away from the player
mc.setBlocks(pos.x + 5, pos.y, pos.z, pos.x + 5, pos.y + numberOfBlocks, pos.z, block.STONE)
#Main Program Starts Here:
createTower(10)
Use any of the three methods mentioned above and complete the code to create a full rugby post using Python.
Try to build a Pyramid first starting from a 10 by 10 square base.
Or why not challenge yourself to build a castle like this one:

This tutorial is the first tutorial in a series of five Pygame tutorials:
Now that you have learned the basics of Python you are most likely willing to start creating your own games. Pygame is one of the best libraries to create mainly 2D retro arcade games such as Tetris, PacMan or Space Invaders.
Let’s see what are the first few steps needed to create your first game in Python.
# Import the pygame library and initialise the game engine import pygame pygame.init()
Note that you will first need to install the Pygame library on your computer. Alternatively you can complete this challenge online using the following Trinket/Pygame IDE
# Define some colors BLACK = ( 0, 0, 0) WHITE = ( 255, 255, 255) GREEN = ( 0, 255, 0) RED = ( 255, 0, 0)
# Open a new window
size = (700, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("My First Game")
The main program loop will contain 3 main sections:
The main program loop will also use a frame rate to decide how often should the program complete the loop (& refresh the screen) per second. To implement this we will use the clock object from the pygame library.
The main program loop will use a timer to decide how many times it will be executed per second.
# The loop will carry on until the user exits the game (e.g. clicks the close button).
carryOn = True
# The clock will be used to control how fast the screen updates
clock = pygame.time.Clock()
# -------- Main Program Loop -----------
while carryOn:
# --- Main event loop
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
carryOn = False # Flag that we are done so we can exit the while loop
# --- Game logic should go here
# --- Drawing code should go here
# First, clear the screen to white.
screen.fill(WHITE)
#The you can draw different shapes and lines or add text to your background stage.
pygame.draw.rect(screen, RED, [55, 200, 100, 70],0)
pygame.draw.line(screen, GREEN, [0, 0], [100, 100], 5)
pygame.draw.ellipse(screen, BLACK, [20,20,250,100], 2)
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 60 frames per second
clock.tick(60)
#Once we have exited the main program loop we can stop the game engine:
pygame.quit()
Complete the code to draw the following background:


file = open("myTextFile.txt","r")
file = open("myFolder/myTextFile.txt","r")
| Mode | Description |
|---|---|
| r | Opens a file in read only mode. This is the default mode. |
| r+ | Opens a file for both reading and writing. |
| w | Opens a file for writing only. Overwrites the file if the file exists. If the file does not exist yet, it will create the new file for writing. |
| w+ | Opens a file for both writing and reading. Overwrites the file if the file exists. If the file does not exist yet, it will create the new file for writing. |
| a | Opens a file for appending. The file pointer is at the end of the file. So new data will be added at the end of the file. If the file does not exist, it creates a new file for writing. |
| a+ | Opens a file for both appending and reading. The file pointer is at the end of the file. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing. |
file.close()
file = open("myTextFile.txt","r")
for line in file:
print(line)
file.close()
file = open("myTextFile.txt","r")
for line in file:
data = line.split(";")
print(data[0] + " - " + data[1] + " - " + data[2])
file.close()
Be careful, when using the write command, you are overwriting the content of your file. If instead of overwriting the content of your file you want to append (write at the end of the file) check the next tab: “Append to a text file”.
Note that when opening the text file, if the file specified does not exist, Python will create a new file automatically.
file = open("myTextFile.txt","w")
file.write("Hello World\n");
file.close()
The “\n” at the end of the text means “new line”. Only use it if you want the next call to the write() method to start on a new line.
To append to a text file you will need to:
file = open("myTextFile.txt","a")
file.write("Hello World\n");
file.close()
The “\n” at the end of the text means “new line”. Only use it if you want the next call to the write() method to start on a new line.

You can download this text file:
countries.txt

For this challenge we are focusing on a set of equations used to draw different sections of the Batman logo:
We will import two Python libraries:

In this challenge you will also use string concatenation techniques.
Finally you will also learn about the following tags in HTML:
<UL> <LI>First bullet point,</LI> <LI>Second bullet point,</LI> <LI>and so on...</LI> </UL>
Using Python we have written a script that prompts the user to enter the number of bullet points they need. In return the script produces the HTML code for the user to copy and paste to their webpage.
A table (<TABLE>) is made of rows (<TR>). Each row is made of data cells (<TD>).
So for instance a 3×2 table contains 3 rows and each row contains 2 data cells. The HTML code of such a table is as follows:

This is the full code in HTML:
<TABLE> <TR> <TD> ... </TD> <TD> ... </TD> </TR> <TR> <TD> ... </TD> <TD> ... </TD> </TR> <TR> <TD> ... </TD> <TD> ... </TD> </TR> </TABLE>
Check this other example of table from w3schools.
Update your code to ask for additional settings such as:
Your program should then generate the HTML code for the table, including the given parameters using HTML or CSS attributes.

Knowing that Circumference = π x Diameter we can calculate π as follows: π = Circumference / Diameter.

As you may have noticed, this method does not give you the exact value of Pi. This due to the fact that the measurements of the diameter and of the circumference of an object are never 100% accurate.
You can try your algorithm with the following measurements:

