More results...

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

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: ,

Flowchart to Python Code – Star Rating Validation

The aim of this Python challenge is to validate a user input using a range check.

In this program, the user will be asked to enter a star rating by entering a number value between 0 and 5. This could for instance be used to rate a movie (5 Stars = Excellent , 0 Star = Disappointing).

The program will check that the end-user has entered a number between 0 and 5 and if not, it will display an error message and repeat the question until a valid rating between 0 and 5 is entered.

Here is the flowchart for our algorithm:
flowchart-star-rating-validation

Python Code


You can now complete the Python code to implement this algorithm.

This algorithm is a good example of:
iteration-label

Testing


Now that your code is complete, it is important to test it to see if it is working as expected.

When testing a program, you can use different types of test and test data:

  • Valid Tests: To check that the program is working fine with acceptable data.
  • Extreme Tests: To test how your program works when you enter data that is at the limit (lower boundaries, upper boundaries) of what is considered acceptable data.
  • Erroneous Tests: To try to break the pogram, enter data that is not acceptable, that should be rejected and/or generate an error message.
Test # Type of Test Input Values Expected Output Actual Output
#1 Valid Star Rating: 2 Thank You
#2 Valid Extreme Star Rating: 0 Thank You
#3 Valid Extreme Star Rating: 5 Thank You
#4 Erroneous Star Rating: 9 Invalid Star Rating – Try Again
Enter a star rating between 0 and 5:
#5 Erroneous Star Rating: -2 Invalid Star Rating – Try Again
Enter a star rating between 0 and 5:
#6 Erroneous Star Rating: xyz Invalid Star Rating – Try Again
Enter a star rating between 0 and 5:

Extension Task


Did you all your test pass? If not, this means your code could be further improved.

Check this blog post to see if it could help you improve your code further and ensure all tests pass.

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 to Python Code – Poker Dice Game

The aim of this challenge is to create a simplified game of Poker Dice using only three dice.
The computer will generate three random numbers between 1 and 6.

The program will then check to see if the three dice have the same value (“Three of a kind!”) or if any two of the three dice have the same value (“Pair”).

The game will be implemented using the following algorithm:
flowchart-poker-dice

Python Code

Use the above flowchart to help you write the Python code to solve this challenge.

This algorithm is a good example of:
selection-label

Extension Task


Could you improve your code further to find out if:

  • The 3 dice are all even numbers.
  • The 3 dice are all odd numbers.

Tip:
To find out if a die number is even you could check whether it is equal to 2, 4 or 6.

Pseudocode:

IF (die1==2 OR die1==4 OR die1==6) AND (die2==2 OR die2==4 OR die2==6) AND (die2==2 OR die2==4 OR die2==6) THEN
   DISPLAY("You have three even numbers.")
END IF

Another method would be to use [lists] and the keyword “in“:

Pseudocode:

IF die1 in [2,4,6] AND die2 in [2,4,6] AND die3 in [2,4,6]  THEN
   DISPLAY("You have three even numbers.")
END IF
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 to Python Code – Discount Price Calculator

discountShopping during the sales can sometimes be very confusing. With discounted prices at 10%, 20%, 50% or even 70%!

For this challenge you are going to write a Python script that prompts the user to enter a price in pounds (or in your own currency) (e.g. ÂŁ90) and a discount rate to apply (e.g. 20%).

Your program will then calculate and display the discounted price.

We will use the following algorithm for our program:
flowchart-discount-price-calculator

Python Code


This algorithm is a good example of:
sequencing-label

Testing


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

Test # Input Values Expected Output Actual Output
#1 Price: ÂŁ100
Discount Rate: 25%
Discount: ÂŁ25
Discounted Price: ÂŁ75
#2 Price: ÂŁ160
Discount Rate: 40%
Discount: ÂŁ64
Discounted Price: ÂŁ96
#3 Price: ÂŁ180
Discount Rate: 10%
Discount: ÂŁ18
Discounted Price: ÂŁ162
Tagged with:

Flowchart to Python Code – Temperature Converter

Fahrenheit-CelsiusDegree Fahrenheit (°F) and Degree Celsius (°C) are the main two units to measure temperature.

The Fahrenheit scale is used mainly in the USA whereas other countries tend to use the Celsius scale.

It is possible to convert a temperature from Celsius degrees to Fahrenheit and vice-versa using the following conversion formulas:
fahrenheit_to_celsius_formulas

Your Challenge


Use the following flowchart to write a Temperature Converter in Python. Your script will:

  • Ask the end-user whether they want to convert from Celsius to Fahrenheit or from Fahrenheit to Celsius,
  • Ask the user to enter a temperature in the correct unit,
  • Apply the conversion formula and display the temperature in the new unit.

flowchart-temperature-conversion

Python Code


This algorithm is a good example of:
selection-label

Testing


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

Test # Input Values Expected Output Actual Output
#1 Option 1
10°C
50°F
#2 Option 1
0°C
32°F
#3 Option 1
-5°C
23°F
#4 Option 2
50°F
10°C
#5 Option 2
32°F
0°C
#6 Option 2
23°F
-5°C
#4 Option x Invalid option!
unlock-access

Solution...

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

Minecraft – Crafting Table

pickaxeFor this blog post we have recreated the crafting table in Minecraft using HTML, CSS and JavaScript.

This crafting table enables you to pick up items from your inventory to recreate some of the key recipes to craft new items and add these new items to your inventory.

Our version of the inventory is simplified as it does not record the quantity of items you have left. For each item listed in your inventory it is assumed that you have an infinite supply.

The purpose of this challenge is for you to investigate and reverse engineer how this code works.

First you may want to try this code with a few recipes:
recipe-Wood-Plank
recipe-Stick
recipe-swords

HTML, CSS and JavaScript Code

See the Pen Minecraft Crafting by 101 Computing (@101Computing) on CodePen.


Your Task


You can then adapt this code to add a few more recipes such as the recipe to craft a compass:
recipe-Compass
And the recipe to craft a clock:
recipe-Clock

Note that you will find here a full list of Minecraft items.

For more crafting recipes, check this page.

Extra Challenge


The next step would be to tweak this code further to display and update the quantities available for each item in the inventory. These quantities should be reduced when items are used to craft new items, and increased when newly crafted items are added to the inventory.

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.