联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-10-15 10:41

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


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp