Question : Description Write two functions that will convert temperatures back and forth from the Celsius and Fahrenheit temperature scales. The formulas for making the conversion are as follows: Tc=(5/9)*(Tf-32) Tf=(9/5)*Tc+32 where Tc is the Celsius temperature and Tf is the Fahrenheit temperature. More information and further descriptions of how to do the conversion can be found at this NASA Webpage. If you finish this assignment quickly, add a function to calculate the wind chill. Input Your program should ask the user to input a temperature and then which conversion they would like to perform. Sample session Temperature converter Enter a temperature: 20 Convert to (F)ahrenheit or (C)elsius? F 20 C = 68 F |
#! /usr/bin/env python
# Tc=(5/9)*(Tf-32)
# Tf=(9/5)*Tc+32
# Tc Celsius temperature and Tf is the Fahrenheit temperature.
def Fahrenheit_temperature(b):
return (( 9/5 )*(b + 32))
print "Temperature converter"
s = int(raw_input('Enter a temperature:')) #int() str -> int
x = raw_input("Convert to (F)ahrenheit or (C)elsius?" )
if ( x == 'F' or x == 'f' ):
print s, "C =" ,Fahrenheit_temperature(s), "F"
else:
print Fahrenheit_temperature(s) , 'F =' , s, 'C'
Reference :
http://openbookproject.net/pybiblio/practice/wilson/tempfinder.php
0 意見:
張貼留言