More results...

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

Area Calculator Flowchart Challenge

In this challenge you will design an algorithm to calculate the area of various shapes as listed below:

Shape Name Area
area-square Square width2
area-rectangle Rectangle width x length
area-circle Circle pi x radius2
area-triangle Triangle base x height / 2

Your algorithm should:

  • Ask the user which of the above four shapes they would like to calculate the area of,
  • Based on the chosen shape, your algorithm should ask the end user to enter the required dimensions (e.g. width, or width and length or radius or base and height),
  • Calculate and display the area of the chosen shape.

Flowchart Challenge


Use our flowchart desing tool to create the flowchart of your algorithm.

Online Flowchart Creator

Python Challenge


Once you have completed your flowchart, you can implement this algorithm using Python code.

Test Plan

Test # Input Values Expected Output Actual Output
#1 Square
Width: 5
Area: 25
#2 Rectangle
Width: 4
Length: 6
Area: 24
#3 Circle
Radius: 10
Area: 314.159
#4 Triangle
Base: 7
Height: 4
Area: 14

Extension Task


Complete your algorithm to cater for additional shapes including parallelograms, rhombus and hexagons.
unlock-access

Solution...

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

Min, Max, Mean, Median and Mod – Flowcharts

In this challenge we will design algorithms used to calculate the Min, Max, Mean, Median and Mod from a list of numbers.

First you may want to refresh your maths skills and check the meaning of these terms: http://www.purplemath.com/modules/meanmode.htm

MIN Flowchart


min-flowchart

Challenge #1


Use our flowchart designer tool to create 4 more flowcharts to:

  • Calculate the Max value of a given list,
  • Calculate the Mean value of a given list,
  • Calculate the Median value of a given list,
  • Calculate the Mod value of a given list.
Online Flowchart Creator

Challenge #2


Now that you have designed your algorithms you can implement these using Python code.

unlock-access

Solution...

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

Fizz-Buzz Game Algorithm

fizz-buzz-iconFizz-Buzz is a group word game for children to teach them about division. Players take turns to count incrementally, replacing any multiple of three with the word “fizz”, and any multiple of five with the word “buzz”.

Fizz-Buzz Challenge


For this challenge you need to write a computer program that will display all the numbers between 1 and 100.

  • For each number divisible by three the computer will display the word “fizz”,
  • For each number divisible by five the computer will display the word “buzz”,
  • For each number divisible by three and by five the computer will display the word “fizz-buzz”,

This is what the output will look like:

    1
    2
    Fizz
    4
    Buzz
    Fizz
    7
    …

Fizz-Buzz Algorithm


Check the following flowchart used to generate the first 100 numbers using the Fizz-Buzz rules. (Click on the flowchart to enlarge it).
flowchart-fizz-buzz

Python Challenge


Use the above flowchart to complete this Python code.

Extension Task #1


Tweak this code to use the input command in Python. The program should ask the user to input numbers in order or type the word Fizz or Buzz when required. The program should check that the user has typed the right number or the right word and stop if not. It should then give the final score (How far the player completed the game).

Extension Task #2


Improve this code further to give the players three lives. The player can make up to 3 mistakes. Each time they make a mistake they lose 10 points but carry on playing till they lose their three lives.

unlock-access

Solution...

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

Finding the factors of…

For this challenge you will use an algorithm to find all the factors of a given number.

Factors are numbers we can multiply together to get another number. For instance, factors of 15 are 1, 3, 5 and 15, because 1Ă—15=15 and 3Ă—5 = 15.

Your algorithm will be based on the INPUT – PROCESS – OUTPUT model:

  • INPUT: Ask the user to enter a number,
  • PROCESS: Identify all the factors of this number,
  • OUTPUT: Display all the factors of this number.

Flowchart


flowchart-factors-of-a-number

Task 1: Python Code


Your task is to implement your algorithm using Python code.

Task 2: Test Plan

Test # Type of Test Input Values Expected Output Actual Output
#1 Valid 12 1,2,3,4,6,12
#2 Valid 21 1,3,7,21
#3 Valid 48 1,2,3,4,6,8,12,16,24,48
#4 Valid 13 1,13

Task 3: Extension Task: Prime Number?

A prime number is a number that has exactly two factors (1 and itself). Which means that a prime number can be divided evenly only by 1, or itself. A prime number must be a whole number greater than 1.

How could you tweak this code to detect if a number is a prime number or not. If a number is a prime number your algorithm should display a message saying so.

Task 4: Extension Task: Simplifying a Fraction


Complete the following two challenges:

unlock-access

Solution...

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

Bidding Process – Flowchart

auction-bidFor this challenge we will consider the bidding process used within online auction websites such as eBay.

Our aim is to create a system that will accept bids from the end-user, check if the bid being placed is greater than the current bid and if so, update the value of the current bid.

Here is the flowchart for our Bidding System: (Click on this flowchart to open in new window)
ebay-flowchart

Making Predictions


Check the above flowchart to understand how this algorithm will work. Based on this flowchart can you answer the following questions?


?
What will be the first question asked to the end user?


?
How does this algorithm decide if a bid is a valid bid or not?


?
How does this algorithm decide when the bidding process ends?


?
What will be the last message displayed to the end-user?

Python Challenge


Your challenge is to use Python code to implement this algorithm.

Extension Task


Check the following two blog posts to see how this code could be improved further by adding validation routines when capturing user inputs. Use these techniques to make your bidding system more robust:

unlock-access

Solution...

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

Tagged with:

Entry Fees Calculator using a Flowchart

For this challenge you will create a flowchart to explain the process that a computer will have to follow to calculate the entry fees to an aqua park for a small group of visitors or a family.

Below is the price list of the aqua park:
Aqua-Park-Price-List

Video Tutorial

Watch the video tutorial for step by step instructions on how to complete this challenge.

Task 1: Design the Flowchart


First you will design the flowchart for your algorithm. The aim is your algorithm is to:

  • Ask the user how many adult tickets are needed,
  • Ask the user how many child tickets are needed,
  • Calculate the total cost of this order,
  • Decide if this order qualifies for a 5% discount and if so, calculate the new total cost of the order,
  • Output the total cost of the order.
Online Flowchart Creator (using Google Chrome)

Task 2: Python Code


Once your flowchart is complete, implement your algorithm using Python code.

Task 3: Test Plan

Test # Type of Test Input Values Expected Output Actual Output
#1 Valid Adults: 2
Children: 1
Total Cost: ÂŁ41
#2 Valid Adults: 1
Children: 0
Total Cost: ÂŁ15
#3 Valid Adults: 2
Children: 3
Total Cost: ÂŁ59.85
#4 Valid Adults: 5
Children: 12
Total Cost: ÂŁ196.65
#5 Valid Extreme Adults: 0
Children: 0
Total Cost: ÂŁ0
#6 Erroneous Adults: abc
Children: xyz
Error Message

Task 4: Adding extra validation routines

Tweak your code to add some validation routines when capturing user inputs. For instance, you want to make sure that the user only enters a positive integer value when asked for the number of tickets required.

You might find this blog post useful to ensure the user provides an integer value when asked to do so.

Adding validation routines when capturing user inputs is always a good approach to improve your programs and make them more robust.

You can investigate other forms of validation routines on this page.

unlock-access

Solution...

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

Flowchart Creator

A flowchart is a visual diagram used to describe an algorithm. It enables you to describe the key steps of your algorithms and highlights when the user will be required to input data, when the computer will output/display information to the end-user, when a decision block (Selection / IF Statement) or a loop (Iteration) is used.

A flowchart uses specific shapes including:

  • Oval shapes to represent the START and END of an algorithm,
  • Parallelogram shapes to represent interactions with the end-user (INPUT and OUTPUT),
  • Rectangle shapes to represent a process or a calculation,
  • Diamond shapes to represent an IF Statement (Selection) or a LOOP (iteration).

Flowchart Task


Try our new online flowchart creator to design your own algorithms.

Recommended Browser: Google Chrome.

To familiarise yourself with this tool, try to reproduce the following flowchart:
star-rating-validation-flowchart

Online Flowchart Creator
Tagged with:

Stacks and Queues using Python

queue-road-signStacks and Queues are two key data structures often used in programming.

A queue is a FIFO data structure: First-In First-Out in other words, it is used to implement a first come first served approach. An item that is added (enqueue) at the end of a queue will be the last one to be accessed (dequeue).

A stack is a FILO data structure: First-In Last-Out. Imagine a stack of books piled up on a table. When you add (push) a book on top of the pile, it will be the first book that you will then take (pop) from the pile (stack).

queue-diagram

stack-diagram

Both stacks and queues can easily be implemented in Python using a list and the append(), pop() and remove() functions.

In the following trinket we are creating our own classes, Queue and Stack. Using Object Oriented Programming (OOP) enables us to prevent direct access to the list (defined as a private attribute – This is an example of encapsulation a key concept in OOP). It also enables us to create and name our own methods, pop(), push(), enqueue() and dequeue() to match the terminology used when using stacks or queues.

Your Task…


Update the above Stack Class and Queue Class to have an extra private property called maxCapacity (positive integer value). This property should be initialised based on a parameter passed using the constructor of each class.

The code to push a value to the Stack or enqueue a value to the queue should be amended to only push or enqueue the value if the stack or the queue have not reached their maximum capacity.

Client-Server Technologies in a Web-Based Application

client-side-scriptingIf you are learning to build websites you will most likely have started learning about HTML, eventually CSS and JavaScript. These three languages are client-side languages which run on your computer through the web-browser.

A website that only relies on client-side languages is called a static website. This means that the webpages remain the same unless you edit the HTML code. To start with (back in the 90s), the World Wide Web was only made of static websites.

Web 2.0

server-side-scripting
Progressively, the internet evolved to more dynamic websites. We call this web2.0.

Websites such as amazon, eBay, Facebook, etc. are dynamic websites. Their content changes constantly based on the user interactions with the site.

Web2.0 websites are full web applications that use both client-side technologies (HTML, CSS, JavaScript) and server-side technologies such as PHP, ASP, .Net, C#, Python, etc. as well as a database to store and retrieve information from (MySQL, Oracle, SQL Server).

Server-side scripts interact with the database using SQL queries to select, update, insert or delete data. They then combine this data with HTML tags to create HTML, CSS and JavaScript code that is then sent to the client computer to be viewed in the web-browser as a static web page would be viewed.

The following diagram summarises some of the key concepts of client-server web-based applications:

client-server-technologies

Relational Databases

Tables, Records & Fields


A table is a collection of records. Each record is made of fields.

Each field has a data type such as String/Text, Integer, Float/Real, Boolean, Date & Time, etc.

A table is a collection of records. Each record is made of fields.

A table is a collection of records. Each record is made of fields.

Primary Keys, Foreign Keys & Relationships

Database-Primary-KeyThe primary key is a unique identifier for each record.
e.g. the candidate number field is a primary key in the student table.

When a primary key is used to link records between two tables, it becomes a foreign key in the linked table.

Relational-Database-RelationshipsThere are 3 types of relationships to link tables:

  • One-to-One Relationships,
  • One-to-Many Relationships,
  • Many-to-Many Relationships.

Entity Relationship Diagram (ERD)


En Entity Relationship Diagram is used to represent all the entities/tables with their attributes/fields and the relationships between these entities.

Database-Entity-Relationship-Diagram

SQL Language

SQL stands for Structured Query Language. SQL is a standard language used to query a relational database. SQL can be used to:

  • SELECT records from one or more tables
  • INSERT new records into a table
  • UPDATE records from a table
  • DELETE records from a table

The basic syntax of the SQL language is as follows:
Database-SQL-Syntax

SQL can also be used to change the structure of a database e.g. creating, editing or dropping tables and indexes.

SQL
Learn how to define your own SQL queries

To recap…

fields
integer
table
records
primary
Boolean
data type
foreign
linked table
identifier
A is a collection of .
Each record is made of


Each field has a such as string/text, , real/float, , date & time, etc.


The key is a unique for each record.

e.g. the candidate number field is a primary key in the student table.


When a primary key is used to link records between two tables, it becomes a key in the .

Tagged with: ,
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.