-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.py
More file actions
92 lines (73 loc) · 2.05 KB
/
modules.py
File metadata and controls
92 lines (73 loc) · 2.05 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import math
root = math.sqrt(99);
flr = math.floor(89.9);
print(str(root) + "\n" + str(flr));
'''
Q2. Import the math module as m.
Use the sqrt() function from the math module to compute the square root of 33. Assign the result to root.
'''
import math as m
root = m.sqrt(33);
print(str(root));
'''
Q3. Import all of the functions from math.
Use the sqrt() function from the math module to compute the square root of 1001. Assign the result to root.
'''
from math import *
root = math.sqrt(1001);
print(str(root));
'''
Q4. Accessing a module variable by using dot
Assign the square root of pi to a.
Assign the ceiling of pi to b.
Assign the floor of pi to c.
'''
a = math.sqrt(math.pi);
b = math.ceil(math.pi);
c = math.floor(math.pi);
print(str(a) + " " + str(b) + " " + str(c));
'''
Q5. Read all of the data from "nfl.csv" into a list variable named nfl using the csv module."
'''
import csv
nfl_file = open("new_nfl.csv");
nfl = list(csv.reader(nfl_file));
#print(nfl);
'''
Q6. Counting the no of wins of "New England Patriots"
header for new_nfl.csv: Year, Week, Winner, Loser
'''
import csv
f = open("new_nfl.csv", "r")
nfl = list(csv.reader(f))
patriots_wins = 0;
for winner in nfl:
if winner[2] == "New England Patriots":
patriots_wins+=1;
print(patriots_wins);
'''
Q7. define function to count the winner based on team_name
'''
import csv
f = open("new_nfl.csv", 'r')
nfl = list(csv.reader(f))
cowboys_wins = 0;
falcons_wins = 0;
# Define your function here.
def nfl_wins(team_name):
if team_name == "Dallas Cowboys":
global cowboys_wins;
for winner in nfl:
if winner[2] == team_name:
cowboys_wins+=1;
return cowboys_wins;
elif team_name == "Atlanta Falcons":
global falcons_wins;
for winner in nfl:
if winner[2] == team_name:
falcons_wins+=1;
return falcons_wins;
cowboys_wins = nfl_wins("Dallas Cowboys");
falcons_wins = nfl_wins("Atlanta Falcons");
print(cowboys_wins);
print(falcons_wins);