Lesson 1: Temperature converter
About this lesson
This is the first in a series of lessons to transition from visual coding to text-based coding with a general-purpose programming language.
Year band: 5-6, 7-8Curriculum Links Assessment
Links with Digital Technologies Curriculum Area
|Processes and Production Skills||5-6||
Design, modify and follow simple algorithms involving sequences of steps, branching, and iteration (repetition) (ACTDIP019)
Design algorithms represented diagrammatically and in English, and trace algorithms to predict output for a given input and to identify errors (ACTDIP029)
Implement and modify programs with user interfaces involving branching, iteration and functions in general-purpose programming language (ACTDIP030)
Students undertake a self-reflection of the programming task. The teacher can use the completed self-assessments to assist in summative assessment.
Did you know that NASA once lost a $125 million spacecraft because two teams were using different units of measurement?
Where do you look when you want to convert:
- inches into centimetres
- degrees Celsius (°C) into degrees Fahrenheit (°F)
- US dollars (USD) into Australian dollars (AUD)?
You may do an Internet search or use a relevant app. Do you think the code used in the program would be complicated? What might it include?
Image credit: WikImages/pixabay
Learning map and outcomes
In this lesson, students will:
- learn basic programming skills to create variables and get user input
- plan and code a program that converts degrees Celsius (°C) into degrees Fahrenheit (°F).
Introduce the task to create a computer program that converts a temperature value in Celsius to a temperature value in Fahrenheit.
As a class, or in teams, design the program as a flowchart. Students must research and fill in the Maths operation. (Temp in Celsius) × 9 ÷ 5 + 32.
Image: Flow chart for temperature converter
Once the flowchart is complete, write the program in pseudocode (structured English). Start with the aim of the program.
#This program converts degrees Celsius (°C) into degrees Fahrenheit (°F) BEGIN Display “Enter the temperature in degrees Celsius:” celsius ← input from user fahrenheit ← celsius × 9 ÷ 5 + 32 Display “The temperature is “, fahrenheit, “ degrees Fahrenheit.” END
Program designers use pseudocode (also called structured English) before coding an algorithm in a real, specific programming language.
The purpose of pseudocode is to clearly understand and communicate an algorithm, regardless of the final language used. Because it translates more readily into real code, it is often more popular than a flowchart.
Pseudocode has few strict rules, but here are some helpful hints to get started:
- Begin your algorithm with BEGIN. End it with END.
- Use a left-pointing arrow (←) to indicate assigning a value to a variable.
eg: income ← 5 × 12 The variable income will now contain the value 60.
At Years 7 and 8, the Australian Digital Technologies curriculum specifies: ‘Design algorithms represented diagrammatically and in English …’ (ACTDIP029). This is further specified as ‘structured English’ in Years 9 and 10 (ACTDIP040).
For more on setting up and choosing a language, see Setting Up.
To review concatenation, variables and user input and output, head back The Basics page.
Step 1: Temperature converter
It’s time to code our temperature converter. This will require storing what the user types in (user input). View the ‘Celsius converter’ video to learn how to create a program to convert temperature. This video covers the entire process of building the code. Solution code is provided for checking.
Step 2: User-friendly output
To make the program more user-friendly, use concatenation – joining text together – for a better output display. View the ‘Celsius converter (concatenation)’ video. This video covers the process of using concatenation to improve output. Solution code is provided for checking.
These challenges use the skills covered so far. By writing or modifying their own programs, students have an opportunity to demonstrate Application and Creation.
- Write out the algorithm in pseudocode first.
Challenge early finishers to try more complex conversions, like capacity (square centimetres to litres) or battery capacity (amp hours to kilowatt hours for a given voltage).
Challenge 2 (Optional)
Have a go at converting currency (eg USD to AUD).
View the ‘Currency converter’ video. This video covers the process of creating a program to convert between USD to AUD. Solution code is provided for checking.
For this conversion, the Google currency converter has an advantage over your own program. Why?
- Online converters often have access to live data on currency conversion rates, which are constantly changing (unlike temperature or other measurement conversions).
- Your program will likely need to rely on a fixed conversion rate for the calculation.
Challenge 3 (Optional)
With more data, more complex calculations can be done. See the two videos below for more challenging ideas.
- Setting up online environments
- Online environments for coding in each language
- Cheat sheets listing basic commands for coding: