Skip to main content
Skip to main content

Visual to text coding Lesson 1:
Temperature converter

Years 5-6; 7-8

This is the first in a series of lessons to transition from visual coding to text-based coding with a general-purpose programming language.

Included videos can be used by a teacher and/or students to see how to code each of the simple programs step-by-step in all three languages: Scratch, Python and JavaScript.

This lesson may take two to three 45-minute periods. It introduces how to create variables, get user input and perform maths operations.

Cross-curricular approach...

This lesson can be used by Mathematics teachers keen to include programming and logical thinking as part of their course. However, it is suggested that students complete The Basics page to familiarise themselves with relevant skills on which this lesson builds.

Next lesson    

Learning hook

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?

Decorative image of a rocket ship launching


Learning map and outcomes

In this lesson, students will:

  1. access an online programming environment for visual code (Scratch) and for general-purpose programming (Python or JavaScript)
  2. learn basic programming skills to create variables and get user input
  3. plan and code a program that converts degrees Celsius (°C) into degrees Fahrenheit (°F).

Learning input

  1. 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.

    Flow chart for temperature converter: Start, leads to 'Ask user for temperature in degrees, celsius', leads to 'Convert temperature into Fahrenheit. Maths operations', leads to 'Display temperature in Fahrenheit', leads to 'End'.

    Image: Flow chart for temperature converter

    1. 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 fahrenheitcelsius × 9 ÷ 5 + 32 Display “The temperature is “, fahrenheit, “ degrees Fahrenheit.” END

Learning construction

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.

To help understand programming Temperature Converter, view this video on concatenation and this video on inputs and outputs.

Solution code:

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.

Solution code:

Step 3: Tinker task

Modify your temperature program to convert the other way – from Fahrenheit to Celsius. Solution code is provided for checking.

Solution code:


These challenges use the skills covered so far. By writing or modifying their own programs, students have an opportunity to demonstrate Application and Creation.

  1. Code a new program in Python or JavaScript that converts centimetres into inches.

    1. Write out the algorithm in pseudocode first.
    2. If it helps, code the program in Scratch before going on to Python or JavaScript. Solution code is provided for checking.

    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).

Solution code:

  1. (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.

    Solution code:


    For this conversion, the Google currency converter has an advantage over your own program. Why?

    Explain that:

    • 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.
  1. (OPTIONAL) With more data, more complex calculations can be done. See the two videos below for more challenging ideas.

    Solution code:


  • Setting up online environments
  • Online environments for coding in each language
    • Scratch
    • an online environment suited to Python
    • JSFiddle: an online environment suited to JavaScript
  • Cheat sheets listing basic commands for coding:
    • Python Cheatsheet (from Grok Learning)
    • JavaScript CheatSheet (Tip: Press the little blue tabs to move Variables, Basics, Strings and Data Types to the top.)