Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b726ef

Browse files
authored
Create lab2.py
1 parent3a17ffe commit1b726ef

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎Module9/lab2.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
importcsv
3+
4+
classIrisReader:
5+
"""
6+
A kinda-sorta rule of thumb is that if you see a Python class
7+
with a single function and an initializer
8+
then it probably shouldn't be a class at all.
9+
Ignore that in this case
10+
"""
11+
12+
def__init__(self,file_path):
13+
self.file_path=file_path
14+
15+
defopen(self):
16+
# TODO3: instead of reading
17+
# the file in everytime
18+
# is there a way to read it in once
19+
# and if it was already read, return
20+
# the existing file data?
21+
try:
22+
f=open(self.file_path)
23+
my_file=csv.reader(f)
24+
returnmy_file
25+
exceptIOError:
26+
print("File not found\n")
27+
returnNone
28+
29+
30+
classIrisStats:
31+
32+
def__init__(self,file_path):
33+
self.sepal_length_column=0
34+
self.petal_length_column=2
35+
self.iris_data=IrisReader(file_path).open()
36+
37+
defget_avg_petal_length(self):
38+
# TODO1: write this function
39+
pass
40+
41+
defget_avg_sepal_length_per_class(self):
42+
# TODO2: write this function
43+
pass
44+
45+
importsys
46+
iris_stats=IrisStats(sys.argv[1])
47+
print(iris_stats.get_avg_petal_length())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp