-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW2.py
More file actions
72 lines (62 loc) · 1.7 KB
/
HW2.py
File metadata and controls
72 lines (62 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#Michael Wellen
totalDistance=float(0)
shotDistance=float(0)
numIndexError=int(0)
numValueError=int(0)
numZeroError=int(0)
numCorrectValue=int(0)
average=float(0)
madeShots=int(0)
result=int(0)
name=str("")
date=str("")
match=str("")
totalRecords=int(-1)
line_number=int(0)
infile=open('test-data.csv','r')
line=infile.readline(line_number)
for line in infile:
if(totalRecords==-1):
totalRecords+=1
continue
try:
totalRecords+=1
row=line.split(',')
result=int(row[4])
shotDistance=float(row[2])
date=str(row[0])
match=str(row[1])
name=str(row[3])
if (name==""):
raise IndexError
if (date==""):
raise IndexError
if (match==""):
raise IndexError
if(result==1):
totalDistance=totalDistance+shotDistance
madeShots+=1
except ValueError:
# print("Value Error",totalRecords)
numValueError+=1
pass
except IndexError:
# print("Index Error",totalRecords)
numIndexError+=1
pass
else:
numCorrectValue+=1
try:
average=float(totalDistance/madeShots);
average=str(round(average,2))
except ZeroDivisionError:
print("There were no shots made, get new data")
numZeroError+=1
finally:
print("Total number of records:",totalRecords)
print("Number of records used:",madeShots)
print("The average made shot is at meters:",average)
print("numValueErrors:",numValueError)
print("numIndexError:",numIndexError)
print("num of Divide by zero errors:",numZeroError)
print("num of correct entries in csv:",numCorrectValue)