Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODE (PLEASE MAKE IT SIMPLE AND WITH FULL COMMENTS AT EACH STEP) Define a Python Class named Steam. The attributes and methods are defined

PYTHON CODE

(PLEASE MAKE IT SIMPLE AND WITH FULL COMMENTS AT EACH STEP)

Define a Python Class named Steam. The attributes and methods are defined below. The behavior of this class will be demonstrated with an example main program that uses the class. The class named Steam has 8 attributes, an three methods: __init__, calc, and print, as defined below:

import numpy as np from scipy.interpolate import griddata

class Steam: def __init__(self, pressure, T=None, h=None, s=None, x=None, v=None, name=None): self.p = pressure # pressure - kPa self.T = T # Temperature - degrees C self.x = x # quality (a value between 0 and 1) self.v = v # specific volume - m^3/kg self.h = h # enthalpy - kJ/kg self.s = s # entropy - kJ/(kg K) self.name = name # a useful identifier self.region = None # 'superheated' or 'saturated' if T==None and x==None and v==None and h==None and s==None: return self.calc() def calc(self): # calculate the missing steam properties using griddata() and the steam tables given earlier.

IMPORTANT:

a)look carefully at the PRESSURE units in the two tables. They are DIFFERENT.

b) Beware of the GAP IN THE DATA problem!

def print(self): # print the available (not None) Steam values

Note: calc(self) should raise errors if asked to do things in cannot handle such as:

raise ValueError('Error - this function cannot operate in the sub-cooled region') raise ValueError('Not enough properties specified')

def main():

inlet=Steam(7350, name='Turbine Inlet')

inlet.x =0.9 # 90 percent quality - accessed

inlet.calc() inlet.print() h1 = inlet.h; s1 = inlet.s

print(h1,s1,' ')

outlet=Steam(100, s=inlet.s, name='Turbine Exit')

#notice - s=inlet.s

outlet.print()

another=Steam(8575, h=2050, name='State 3')

another.print()

yetanother=Steam(8900, h=41250, name='State 4')

yetanother.print()

#uncommenting the next two lines will cause a ValueError error

#final1 = Steam(7000, T=250, name='State 5')

#final1.print()

if __name__ == "__main__":

main()

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

Step: 3

blur-text-image

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

Understand the requirements for diversity management

Answered: 1 week ago

Question

What is operatiing system?

Answered: 1 week ago

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago