JamesBranam's Blog
Python Temperature Converter in NetBeans Python EA - Part 1
Hi everyone,
It's been very cold here lately. The temperature has been far below zero (Celsius) for more than ten days now (it even got down to -20 degrees C where I live, which is -4 degrees C). Often, when speaking to my family in the U.S., I found myself trying to convert temperatures from Celsius to Fahrenheit very quickly. Then I had an idea. You see, lately I've been learning a lot about Python and how to work with Python in the Python EA (Early A
Today I'll be presenting the first part of this tutorial, whcih is basically how to create a simple Python application using NetBeans. I'll add more things to this tutorial later, like user input and validation. So, without further ado, here is the first part of the tutorial. Make sure you have the Python EA version of the IDE before you start.
Creating the Project
First, you create the project using the New Project Wizard.
- In the main toolbar, choose File > New Project.
The New Project wizard opens with Python displayed as the category.
- Select Python Project as the Project Type. Click Next.

- Enter
TemperatureConverteras the Project Name.
The IDE creates a project folder based on the name of the project.
- Select the Python Platform you want to use from the drop down list. Click Finish to create the project.
Note how your project is displayed in the Projects window.
Note that the project is open in the Source Editor of the IDE.

Adding Python Code
In this section, you add Python code to your new project.
- In the Source Editor, erase the existing code the existing code under the
__date__string.The Source Editor should then look like the following image.

- Enter the following code in the source editor.
def temp(): print "Celsius Fahrenheit" # This is the table header. for celsius in range(0,101,10): # Range of temperatures from 0-101 in incrememts of 10 fahrenheit = (9.0/5.0) * celsius +32 # The conversion print celsius, " ", fahrenheit # a table row temp()The Source Editor should now resemble the following image.

Running the Project
Now it is time to run your project. In NetBeans IDE, there are several ways to run your project. You can click the run icon in the main toolbar, or you can right-click the project node in the Projects window and choose Run.
- In the Projects window, right-click the project node and choose Run.
The results are displayed in the Output window at the bottom of the IDE, as seen in the following image.

In part 2 next week, we'll add some more code to provide user input.
See you then.
Cheers!
--James
Posted at 02:58PM Jan 13, 2009 by branajam in NetBeans | Comments[2]
looks like the makings of an excellent tutorial!
Posted by troy on January 13, 2009 at 04:39 PM CET #
i was wondering if you would have any idea on how to do this...The main components of this assignment are threefold - string processing, reading from files, and dictionaries.
Your assignment is to build a unit conversion program that reads all its conversion factors from a file and then alows a user to enter the units to convert from, the units to convert to, and the quantity. An example interaction follows:
Hello! I am a unit conversion program. I can convert many units to
many other units. What would you like to convert from?
I support the following units:
feet
miles
meters
yards
inches
What would you like to convert from? inches
What would you like to convert to? meters
How much would you like to convert? 74.5
74.5 inches in meters is 1.89230000193
The units file I would like you to read is conversion_table.txt (you should download the file and read it locally. Dynamically updating it from the website would be extra credit...). Note that only half of the possible conversions are specified in the file, but the other half can be figured out. In the example above, note that we have the conversion factor from inches to meters in the supplied table, but asked the program to calculate meters to inches.
Posted by jay on February 12, 2009 at 01:18 AM CET #