Question: class UnitError(Exception): pass class Temperature: def __init__(self, temp=0, unit='C'): self.temp = float(temp); self.unit = unit.upper(); if (self.unit.upper()) not in ['C','F']: raise UnitError(Un-recognized temperature unit '

class UnitError(Exception): pass class Temperature: def __init__(self, temp=0, unit='C'): self.temp = float(temp); self.unit = unit.upper(); if (self.unit.upper()) not in ['C','F']: raise UnitError("Un-recognized temperature unit '" + unit + "'"); pass def __repr__(self): return "Temperature("+str(self.temp)+",'"+self.unit+"')"; def __str__(self): return str(self.temp)+chr(176)+self.unit; def convert(self): t = Temperature(); if self.unit.upper() == 'C': t.temp = ((9.0/5.0)*self.temp)+32.0; t.unit = 'F'; else: t.temp = (5.0/9.0)*(self.temp-32.0); t.unit = 'C'; return t def __eq__(self, obj1): if self.unit == obj1.unit : if self.temp == obj1.temp: print(True); else: print(False) else: self = self.convert(); if self.temp == obj1.temp: print(True) else: print(False)

1. In the same module/file, implement a class TempConverter that that provides a GUI for converting temperatures. TempConverter should be a usable widget, to do this it MUST subclass Frame (similar to the Calculator). The GUI can be made visible by executing:

>>> TempConverter().pack()

>>>

Or first creating a root window, then creating and packing

>>> root = Tk()

>>> TempConverter(root).pack()

The following output must be met with no errors:

>>> root = Tk() >>> TempConverter(root).pack() >>> TempConverter(root).pack() >>> root.destroy() >>> t = TempConverter().pack() >>>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!