Head office, Rana Pratap Bagh, Delhi011 2721 1512+91 97116 99511

Science project idea

Python unit converter for length, mass and temperature

The program converts between units using stored factors and the Celsius to Fahrenheit formula. It combines maths with menus and functions.

What it shows

The program converts between units using stored factors and the Celsius to Fahrenheit formula. It combines maths with menus and functions.

The science

To convert units we multiply by a conversion factor: one kilometre is about 0.621371 miles and one kilogram is about 2.20462 pounds. Temperature is different because the scales start at different zeros, so the formula needs both a multiplication and an addition: F = C x 9/5 + 32. Storing factors in a dictionary keeps the code short.

Materials

Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.

  • A computer, laptop or phone with a browser (free)
  • Python 3 with IDLE, or the free Thonny editor, or an online Python runner (all free)
  • A notebook and a pencil

Safety

This project uses safe, everyday materials. Still, read the rules below with a parent before you start.

Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.

All the safety rules

Step by step

8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.

  1. Create convert.py and write factors = {"km to miles": 0.621371, "miles to km": 1.60934, "kg to pounds": 2.20462, "pounds to kg": 0.453592}.

  2. Define def c_to_f(c): with return c * 9 / 5 + 32 and def f_to_c(f): with return (f - 32) * 5 / 9.

  3. Start while True: and print the keys with for k in factors: print(k).

  4. Also print the two temperature options and the word quit.

  5. Read the choice with choice = input("Choose: ").lower() and add if choice == "quit": break.

  6. If choice in factors: ask value = float(input("Value: ")) and print(round(value * factors[choice], 2)).

  7. Add elif branches for the temperature choices that call the two functions and print their result.

  8. Test with known values: 0 Celsius should be 32 Fahrenheit, 100 Celsius should be 212, and 1 mile should be 1.61 km.

What you should see

The program converts the chosen units correctly: 100 Celsius shows 212 Fahrenheit and 10 km shows about 6.21 miles. Unknown choices are ignored.

Viva questions

A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.

1Why can temperature not use only a factor?

The scales have different zero points, so an addition of 32 is also needed.

2How can you check the program?

Test with values you know, such as 0 C is 32 F.

3What is a conversion factor?

The number you multiply by to change one unit to another.

4Why use round?

To show a tidy number of decimal places.

Free ebook: Viva Questions for Science Projects

Take it further

Add a speed conversion from km/h to m/s by dividing by 3.6 and explain why that factor works.

Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.

Free ebooks for this project

Find out more about computing and coding

Free, well-known places to explore the subject further. Ask a grown-up before you sign up for anything or type your name anywhere.

WhatsApp us