讲解Python、辅导Python程序语言、辅导clean_strock_price、Python讲解

- 首页 >> Python编程

Weekly Assignment – Session 3 – 40 pts

Direction: You will be provided with 2 files, shapes.py and app.py. You will alter

these files directly and turn them back in. Do not rename the files. Zip both files in

and upload with the name assignment3_{cnet_id}.zip.

Special Note

1. This assignment focuses on inheritance and subsequently code re-use.

Therefore, unlike past assignments, you will be graded on the code you write

and the code you do not write.

2. Up until now the assignments have not been rigorously tested for handling

bad data. This assignment will be graded on exception handling, i.e. we will

try to break it.

Part 1 (5 pts)

Complete the Rectangle class. It should inherit from Shape and correctly execute the following:

1. __init__

2. getColor

3. setColor

4. getDimensions

5. setDimentions

6. calcArea

7. __repr__

Part 2 (5 pts)

Complete the Square class. It should inherit from Rectangle and correctly execute the

following:

1. __init__

2. getColor

3. setColor

4. getDimensions

5. setDimentions

6. calcArea

7. __repr__

Part 3 (5 pts)

Complete the Triangle class. It should inherit from Shape and correctly execute the following:

1. __init__

2. getColor

3. setColor

4. getDimensions

5. setDimentions

6. calcArea

7. __repr__

Part 4 (5 pts)

Complete the EquilateralTri class. It should inherit from Triangle and correctly execute the

following:

1. __init__

2. getColor

3. setColor

4. getDimensions

5. setDimentions

6. calcArea

7. __repr__

Part 5 (5 pts)

Complete the drawMe() function. Refer to the hist() function written in an earlier assignment.

Part 6 (5 pts)

Add the appropriate exception handling to app.py so that the script completes successfully

without altering the code already provided.

Part 7 (10 pts)

#!/usr/bin/python

#Let's assume you have the current time series for a given stock

stock_price=[12.32, 12.10, 12.12, '12.21', 12.20, 12.20, 12.20,

'number', 12.42, 1.2, 12.65, 12.43, 12.54]

# You need to store this stock into a float variable

a=0.0

# For that, you are going to use an exception to detect when you receive a string instead of a

float

for price in stock_price:

a=float(price)



#create a new list converting string to float except when not possible

#you will assign this new list to clean_stock_price

clean_stock_price=

# you will also create a function raising an exception when this function find an outlier

# use raise Exception('outlier')

def raise_outlier_exception(price_list):

for price in price_list:

# # Check if there is an outlier



# you will now use clean_strock_price as an argument of the function raise_outlier_exception

try:

raise_outlier_exception(clean_stock_price)

except Exception as inst:

print inst


站长地图