Home | Trees | Indices | Help |
|
---|
|
1 # coding=UTF-8 2 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation, either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 from Convert import Converter 1719 """A converter which converts temperature between Fahrenheit and Celsius.""" 20 21 __name__ = 'TemperatureConverter' 22 __title__ = 'Fahrenheit / Celsius' 23 __author__ = 'Arnav Ghosh' 24 __version__ = '0.2' 25 26 num_fields = 2 27 field_names = [u'˚F', u'˚C'] 285330 self.active_field = 0 31 self.values = ['0', '0'] 32 # 0˚F is not 0˚C, let's correct this by a call to convert() 33 # (this leaves '0' on the active field) 34 self.convert()3537 if key.isdigit() or key == '+' or key == '-': 38 return True 39 elif key == '.': 40 return not ('.' in self.values[self.active_field]) 41 else: 42 return False4345 try: 46 val = float(self.values[self.active_field]) 47 except: 48 val = 0 # This handles the case of a single '-' in input 49 if self.active_field == 0: 50 self.values[1] = '%.1f' % ((val - 32) / 1.8) 51 else: 52 self.values[0] = '%.1f' % ((val * 1.8) + 32)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jan 4 16:58:27 2012 | http://epydoc.sourceforge.net |