More results...

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

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:
7⁄4, 12⁄10, 21⁄3 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:
7⁄9, 12⁄21, 3⁄4 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:
31⁄2, 13⁄10, 213⁄4 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 Remainder⁄Denominator

For instance: Let’s convert 11⁄4 into a mixed number

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

11⁄4 = 2 3⁄4

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

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
Privacy Overview

This website will store some information about your preferences on your own computer inside a tiny file called a cookie. A cookie is a small piece of data that a website asks your browser to store on your computer or mobile device. The cookie allows the website to remember your actions or preferences over time.

You can delete all cookies that are already on your computer, and you can set most browsers to prevent them from being placed. However, if you do this, you may have to manually adjust some preferences every time you visit a site, and some services and functionalities may not work.

Most browsers support cookies, but you can set your browser to decline them and can delete them whenever you like. You can find instructions here for how you can do that on various browsers.

This website uses cookies to:

  1. Identify you as a returning user and to count your visits in traffic statistics analysis
  2. Remember your custom display preferences (such as light/dark theme option)
  3. Provide other usability features, including tracking whether you have already given your consent to cookies

Enabling cookies is not strictly necessary for the website to work but it will provide you with a better browsing experience.

The cookie-related information is not used to identify you personally and is not used for any purpose other than those described here.

There may also be other types of cookies created after you have visited this website. This site uses Google Analytics, a popular web analytics service that uses cookies to help to analyse how users use the site. The information generated by the cookie about your use of this website (including your IP address) will be transmitted to and stored by Google on servers in the United States. Google will use this information for the purpose of evaluating your use of other website, compiling reports on website activity, and providing other services relating to website activity and internet usage. Google may also transfer this information to third parties where required to do so by law, or where such third parties process the information on Google’s behalf. Google undertakes not to associate your IP address with any other data held by Google.