More results...

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

Catch Me If You Can

In this challenge we will create a three-player game using Scratch.

One player (the yellow ball) will be chased by two other players the red player and the blue player.

  • The red player will use the arrow keys to control their sprite.
  • The blue player will use the “WASD” keys to control their sprite.
  • The yellow player will use the mouse pointer to control their sprite.

The game will use two score variables one for the red player, one for the blue player. At the start of the game both scores will be initialized to 0. Every time a player collides with the ball their score will be incremented by 1. The ball will then be randomly moved on screen by resetting its x and y coordinates.

Scracth Code


To implement this game you will have to create three sprites and use the code provided below:

Red SpriteBlue SpriteYellow Sprite
The Red Sprite, called Red Dot, will be controlled using the arrow keys:

The Blue Sprite, called Blue Dot, will be controlled using the WASD keys:
The Yellow Sprite, called the Ball, will be controlled using the mouse pointer. it will also have a collision detection algorithm to detect if the ball has been caught by either the red sprite or the blue sprite.

Extension Task: Adding Walls/Platforms


To make this game more interesting we will add walls/obstacles that the red player, the blue player and the yellow ball will have to avoid when moving around.

Step 1: The StageRed SpriteBlue SpriteYellow Ball
Using a plain colour create a background for the stage by adding walls:

Adapt the script of your red sprite so that it cannot go through the walls:
Adapt the script of your red sprite so that it cannot go through the walls:
Adapt the script of your yellow sprite so that it cannot go through the walls:
Tagged with: ,

Recursive Tree Challenge

Look at the code provided below use to draw a tree using a recursive function.

Recursive Function


A recursive function is an alternative to using iteration. A function is a recursive function if:

  • It includes a call to itself,
  • It has a stopping condition to stop the recursion.

In the code given below the drawTree() function is a recursive function because:

  • It includes a call to itself (on line 10 and also on line 13)
  • It has a stopping condition on line 7 (it will stop recursing when level reaches 0)

Your Challenge


Tweak the code provided above to create different versions of recursive trees. You could investigate having three branches per node instead of two or using some random attributes so that the tree becomes less symmetrical.

recursive-tree-1

Mixed Numbers Challenge

Before completing this challenge we need to revise some Maths concepts.

Fraction = numerator / denominator


In Maths a fraction consists of two numbers: a numerator and a denominator.

What is an improper fraction?


An improper fraction is a fraction where the numerator is greater than or equal to the denominator.

For instance:
74, 1210, 213 are all improper fractions.

What is a proper fraction?


A proper fraction is a fraction where the numerator is lower than to the denominator.

For instance:
79, 1221, 34 are all proper fractions.

What is a mixed number?


A mixed number is a number consisting of a whole number and a proper fraction.

For instance:
312, 1310, 2134 are all mixed numbers.

Converting improper fractions into mixed numbers


We can easily convert an improper fraction into a mixed number by calculating the quotient and the remainder from the improper fraction.

Mixed number = Quotient RemainderDenominator

For instance: Let’s convert 114 into a mixed number

Step 1: Quotient (Whole Division): 11 DIV 4 = 2
Step 2: Remainder: 11 MOD 4 = 3

114 = 2 34

Quotient & Remainder in Python?


In Python you can use the // operator to calculate the quotient of a fraction and the % operator to calculate the remainder of a fraction.

For instance:

quotient = 11 // 4
remainder = 11 % 4

Python Challenge #1


Complete the code given below to convert an improper fraction into a mixed number by:

  1. Check that the user has entered a numerator and a denominator for an improper fraction. (The numerator should be greater or equal to the denominator).
  2. Calculate and display the mixed number corresponding to the given fraction.

Python Challenge #2


Create a Python script to convert a mixed number into an improper fraction.
unlock-access

Solution...

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

Text Alignment Challenge


This challenge focuses on the use of string manipulation techniques in order to format the output when printing text on the screen.

Step 1: Reverse Engineering


First look at the code provided above and use this code to answer the following questions:

  1. Which line of code will be executed first by the computer when you run this code?
  2. What data structure is used to store a selection of European capital cities?
  3. What is the identifier of the procedure defined in this code?
  4. How many parameters this procedure takes?
  5. What programming construct is this procedure based on? Sequencing, Selection or Iteration?
  6. What data will be stored in the itemLength variable?
  7. What is the data type for this value: String, Boolean, Integer or Float?
  8. What data will be stored in the spaces variable?
  9. What is the data type for this value: String, Boolean, Integer or Float?
  10. String concatenation is the act of joining two strings together (using the + sign). Which line of code is using string concatenation is this program?

Step 2: Complete the Code


Using a similar approach to the code given to implement the leftAlign procedure create two more procedures as follows:

  • rightAlign to display all the European capitals aligned to the right.
  • centerAlign to display all the European capitals centred on screen.

Step 3: Extension Task Task


-lorem ipsum.txt –

Write a Python program to read and display the content of the above text file:

  • Align to the left,
  • Align to the right,
  • Centred,
  • Justified,
  • Using Auto-hyphenation.
unlock-access

Solution...

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

3D Printing – Name Badge

One application of programming is to control 3D printers to create 3D models. Using a Block programming language you can create your own 3D models and export them in a format recognised by 3D Printers. In this blog you will create a 3D model of your name or initials using http://www.beetleblocks.com/.

We have To get you started we are showing the code that would be used to create two leetes: Letter C and letter A.

You will need to use a similar approach to create a 3D model of your initials or of your full name.

Letter C


3D-Printing-Letter-C

Letter A


Letter A

Students’s Code


Tagged with: ,

3D Printing: Bracelets

One application of programming is to control 3D printers to create 3D models. Using a Block programming language you can create your own 3D models and export them in a format recognised by 3D Printers. In this blog we will create some bracelets using http://www.beetleblocks.com/.

We have made 2 Bracelets that you can easily reproduced and tweak to create your own bracelet.

Notice how both Bracelets use iteration (repeat block) which make the code very short and effective to produce a complex 3D model.

Bracelet #1


Bracelet #2


Tagged with: ,

Conway’s Game of Life

Game_of_life_pulsarThe “game” is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves, or, for advanced “players”, by creating patterns with particular properties.

The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead, or “populated” or “unpopulated”. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

  • Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any live cell with more than three live neighbours dies, as if by overpopulation.
  • Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.

You can read more about Conway’s Game of Life on wikipedia.

Python Implementation


Our Python implementation of Conway’s Game of Life lets you try different starting configurations as follows:

  • Option 1: Random configuration using a randomly generated 15×15 grid.
  • Option 2: The Glider Configuration.Glider
  • Option 3: The Toad Configuration.Toad
  • Option 4: The Beacon Configuration.Beacon
  • Option 5: The Pulsar configuration.Pulsar

Your Challenge


Compete the code provided in the trinket above to add some additional configurations such as:

  • The BlinkerBlinker
  • The PentadecathlonPentadecathlon
  • The Lightweight SpaceshipLightweight Spaceship

3D Staircase Challenge

In this challenge you will use http://www.beetleblocks.com/ to create some 3D models to represent different types of staircases. I will use iteration (for loops) to make your code more effective and investigate the use of (x,y,z) coordinates to create your models.

Another approach for this challenge is to complete the following tasksheet to match the code with the corresponding 3D model:

– 3D-Staircase-Challenge.pdf –

Staircase #1


ChallengeSolution

Staircase #2


ChallengeSolution
staircase-2-3d-model

Staircase #3


ChallengeSolution


Staircase #4


ChallengeSolution


Staircase #5


ChallengeSolution


Tagged with: , , ,

Space Exploration – 3D Models

Computer code can be used to create 2D or 3D graphics. The code used to create these graphics can then be used by 3D printers to create objects.

In this challenge we will use block programming to create a 3D model of a space station or a lunar habitat.

Here are some models to be used as a source of inspiration:
Apolo-Soyuz

Apolo Soyuz

Habitat_Demo_Unit
Habitat Demo Unit

Skylab-3D
Skylab

Your Challenge


To recreate your own Space Exploration 3D Model online you will need to access: http://www.beetleblocks.com.

You can create your own model from scratch or reuse the code provided below to get started:
3D-Space-Exploration

3D-Space-Exploration-Code

Tagged with: , ,

Python Wordsearch Generator

wordsearchFor this challenge we will write a Python program to randomly generate a 12 by 12 wordsearch where computing words will be randomly positioned on the grid and will appear either horizontally, vertically or diagonally.

We have started the code for you but one of our subroutine is incomplete. This is the addWord() subroutine used to position a word on the wordsearch. Your task is to complete the code to:

  • Decide where the word will start (random row and column)
  • Decide if the word will be added horizontally, vertically or diagonally
  • Check that the word will fit in (within the 12 by 12 grid)
  • Check that the word will not overlap with existing letters/words in the wordsearch

Complete the Code


Extension Task


Add two constants called ROWS and COLS both sets to 12. Make sure you declare and initialise these constants at the very beginning of your code.

Ensure that your code is using these constants throughout so that you can easily change the final size of the wordsearch by changing these two values only once at the beginning of your code.

unlock-access

Solution...

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