Kenno's openNOTE

My Programming Weblog

Temperature Conversion

with 2 comments

If you get used to read the temperature in Fahrenheit scale like me, you may be confusing to see the temperature in Celsius scale given in weather forcasting on Australian or New Zealand televisions.

So today, I'm gonna show you a small Python program which can be used to convert the temperature scale from Fahrenheit to Celsius. As my Python programming skill is very limited at the moment, the program is going to perform very basic function.

As usual, open your text editor program, copy or type the following code and save it to convertctof.py.

# convertctof.py
# A program to convert the Celcius to Fahrenheit scale
# by: kenno.wordpress.com

def main():
    celsius = int(raw_input("What is the Celsius temperature? "))
    fahrenheit = 9.0 / 5.0 * celsius + 32
    print "The temperature is ", fahrenheit, " degrees Fahrenheit."
main()

Here is an example:

kenno$ python convertctof.py
What is the Celsius temperature? 22
The temparature is 71.6 degrees Fahrenheit.

Written by kenno

April 6, 2006 at 5:16 am

Posted in Uncategorized

2 Responses

Subscribe to comments with RSS.

  1. Awesome Thanks! I’m taking a course in basic python and this helped me out a lot for my homework.

    pr0gambl3r

    August 19, 2011 at 1:43 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.