Wednesday, 27 April 2011

fahrenheit to celcius and celcius to fahrenheit program in python

hi,

i am new to the python scripting.

today i tried farenheit to celcius and celcius to fahrenheit to celcius conversion in python.

it was really easy and fun to work with python

the code is:

#! /usr/bin/python

print "enter 'c' to convert fahrenheit to celcius"
print "enter 'f' to convert celcius to fahrenheit"
x = raw_input("c or f:")
if x == 'c':
    fahren = float(raw_input("please enter a value:  "))
    cent = ((fahren-32)*5)/9
    print float(cent)
elif x == 'f':
    cen = float(raw_input("please enter a value:  "))
    fahrenh = ((cen*9)/5)+32
    print float(fahrenh)
else:
    print "invalid input :( sorry try again"

i have also added some screen shots for reference :)

No comments:

Post a Comment