More results...

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

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

London Bus Timetable

london-tourFor this challenge, we will write a Python script to extract relevant information from a bus timetable to help end-users plan their journey.

Check the following timetable to answer the questions listed below:
bus-timetable

  • At what time will I reach Buckingham Palace if I take the 11:45 bus from St Paul’s Cathedral?
  • At what time will I reach Oxford Circus if I take the 14:44 bus from Tower Bridge?
  • I am planning to finish the visit of Tate Modern around 10:00? What would then be the earliest time for me to be at Covent Garden?

Python Challenge


We have started some code to load the content of the above timebale into a 2-dimensional array (list of lists in Python) called timetable.

Your task is to complete the code to:

  • Asks the user for the bus station they will take the bus from,
  • Asks the user at what time they will be at the bus station,
  • Asks the user where do they want to go,
  • Outputs the earliest time the user can reach their destination.


unlock-access

Solution...

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

Offside Detection Algorithm

In a game of football, one of the most complex rule is the offside rule. One of the roles of the assistant referees is to detect when a player is offside.

A player is in an offside position if, when the ball is played by a team-mate, they are nearer to the opposition’s goal line than both the ball and the second last defender (the last defender being in most cases the goal keeper).

Note that players cannot be offside in their own half of the field.

In this challenge, we assume that the blue team has the ball and want to identify if any of the players of the blue team is in a position of off-side. We will assume that the ball is being played by a team-mate positioned behind them.

Python Challenge


In this challenge you will design an algorithm to detect if a player is offside. You will implement this algorithm in Python by completing the code provided below.

Your algorithm will need to:

  • Loop through all the players of the red team (away team) to find out the y coordinate of the second last defender,
  • Loop through all the players of the blue team (home team) to find out the y coordinate of the most forward player,
  • Compare both these y coordinates to decide if there is a position of offside,
  • Output a message on screen or draw a horizontal line to show which player is offside.


unlock-access

Solution...

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

Connect4 Challenge

connect4In this blog post you will use HTML, CSS, and JavaScript to complete this game of connect 4 for two players. (Rules of the game)

You will first need to reverse-engineer the code provided. The code so far is used to:

  • Display the 6×7 grid using HTML and CSS.
  • Add a token on the bottom row of the grid when the user clicks on a column of the grid using the selectColumn()
    function in JavaScript.
  • Refresh the grid on the screen using the refreshGrid() function in JavaScript.

The code provided uses a variable called grid, use to store a two-dimensional array (6×7) of integer values. Within this array, a 0 represents an empty place, a 1 represents a yellow token and a 2 represents a red token.

2-dimensional array

Your Task


Your task consists of:

  • Amend the selectColumn() function in JavaScript in order to:
    • Check if the column is not already full and if it is ask the user to chose another column.
    • Place the token on top of any existing token in the selected column.
    • Check if after placing the token the game continues or if the player has aligned 4 tokens. (Current player wins!)
    • Check if the grid is full (Game ends on a draw!)
  • Add code to the resetGrid() JavaScript function to start a new game with an empty grid.

HTML, CSS and JavaScript Code

See the Pen Connect4 Challenge by 101 Computing (@101Computing) on CodePen.

Tagged with: , , , , ,

Water Polo Challenge

water-poloIn this challenge you are going to use Python code to score a goal in a game of Water Polo.

To do so you will use the code given below. You will pass the ball from one player to another using a subroutine called throwBall(). This subroutine takes two parameters as follows:

  • angle: an integer value between 0 and 360 degrees to represent the direction of the throw. (e.g 0° would throw the ball to the right, 90° straight ahead and 180° to the left).
  • power: an integer value between 0 and 200 representing how far you can throw the ball.

This diagram will help you identify your angles when throwing the ball:angle-0-to-360

In this challenge you have the red team. Make sure than, when passing the ball or trying to score a goal (in the goal at the top), you do not throw the ball over a white player who would then intercept it. Also make sure that each throw either reach a team member (red team) or the top goal.

Complete the code to score a goal


Tagged with: , ,

Logic Gates & Truth Tables

Learning Objectives


In this post you will predict the output of logic gates circuits by completing truth tables. First you need to learn the basic truth tables for the following logic gates:

  • AND Gate
  • OR Gate
  • XOR Gate
  • NOT Gate

First you will need to learn the shapes/symbols used to draw the four main logic gates:

Logic Gate Truth Table
AND-GateAND AND Gate Truth Table
OR-GateOR OR Gate Truth Table
XOR-GateXOR XOR Gate Truth Table
NOT-GateNOT truth-table-not-gate

Your Task


Your task is to complete the truth tables for the following diagrams. You can click on the Truth Tables to change the values in the X column.

Tagged with: , ,

Football Formation

football-team-formationThe purpose of this challenge is to understand how subroutines (functions/procedures) are used in Python to create sections of code that can be called/reused many times within a program. Subroutines mean that a section of code can be identified using a name (identifier). This enables us to add more instructions to the already existing functions used in Python such as print or input.

To create a new subroutine in Python we have to declare it first using the keyword def in Python.

e.g.:

def drawPlayer():

The code for the subroutine is then indented to the right.

A subroutine can also take parameters. In our case, our drawPlayer() subroutine will take four parameters:

  • color: (string value) The color name such as “red” or hexadecimal code such as “#FF0000”.
  • x: (integer value) The x coordinate of the player between -140 to 140,
  • y: (integer value) The y coordinate of the player between -195 to 195,
  • label: (string value) The text (name of player or position) to display.

X and Y coordinates? Quadrant?


xy-coordinates
Check the above picture. Can you state three facts about X and Y coordinates and about quadrants?

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:

So to define this function we will now be using the following code with the 4 parameters:

def drawPlayer(color,x,y,label):

We will then be able to position our players by calling the drawPlayer() subroutine as follows:

drawPlayer("red",60,120,"Goal Keeper")

Your task consists of adding all 11 players to your formation using the code provided below. We have already started the formation for you by adding the goal keeper and the two centre-back players.

Your formation should include 11 players including:

  • 1 goal keeper,
  • 2 to 4 fullback players,
  • 2 to 4 midfield players,
  • 2 to 4 forward players.

football-formation

Extension Task #1


Add a parameter to the drawPlayer() subroutine to take the squad number of the player.

Change the content of the subroutine to display the squad number on the circle for the player. The output of your program should look like this:

Extension Task #2


During a football games, players can be issued a yellow card or a red card.

Add two parameters to your subroutine to specify if a player has been given a yellow or red card.

Change the text color of the player name or position to:

  • Yellow for players who have received a yellow card,
  • Red for players who have received a red card,
  • Grey (#CCCCCC) for all other players.
Tagged with: , , , , ,

Acute, Obtuse and Reflex Angles

Angles are often used in Computer Science especially when creating 2D or 3D user interfaces. Angle measurements are given in either radians or degrees. In this blog post we will use degrees. As the angle increase, the name of the angle changes as explained in the pictures and in the table below:

types-of-angles

Type of Angle Description
Acute Angle an angle that is less than 90°
Right Angle an angle that is 90° exactly
Obtuse Angle an angle that is greater than 90° but
less than 180°
Straight Angle an angle that is 180° exactly
Reflex Angle an angle that is greater than 180°

Challenge #1


Write a Python script that will ask the user to enter an angle between 0° and 360°.

The program should find out and output the type of angle (Acute, Right, Obtuse, Straight or Reflex) using the table of values provided above.

Video Tutorial


Test Plan


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

Test # Input Values Expected Output Actual Output
#1 Angle: 30 Acute angle
#2 Angle: 90 Right angle
#3 Angle: 105 Obtuse angle
#4 Angle: 180 Straight angle
#5 Angle: 210 Reflex angle
#6 Angle: 420 Please try again with an angle value between 0 and 360 degrees.

Challenge #2: Quiz


Write a Python script that will generate a random angle between 0° and 360°. The program should ask the user to give the name of the angle. If the user gets it right they should score 1 point.

The program should repeat this process ten times and output a final score out of ten.

To complete these two challenges you will need to use some selection statements (IF,ELIF,ELSE statements) as well as some comparison operators and Boolean operators (AND, OR, NOT).

The main comparison operators are:

Comparison Operator Meaning Example
== is equal to 4==4
!= is different from 4!=7
< is lower than 3<5
> is greater than 9>2
<= is lower or equal to 3<=5
5<=5
>= is greater or equal to 9>=2
5>=5
unlock-access

Solution...

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