Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

What is electric dipole explain with example

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago