Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions q01_read_data/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# %load q01_read_data/build.py
import yaml

def read_data():

# import the csv file into `data` variable
# import the csv file into variable
# You can use this path to access the CSV file: '../data/ipl_match.yaml'
# Write your code here
fileData = open('./data/ipl_match.yaml','r')
yamlData = yaml.load(fileData.read())
print(type(yamlData) )
data = yamlData
print(data)
return data

read_data()
import sys, os
sys.path.append(os.path.join(os.path.dirname(os.curdir)))

from unittest import TestCase
from q01_read_data.build import read_data

class TestRead_data(TestCase):
def test_return_instance(self):
result = read_data()
self.assertIsInstance(result, dict,'The expected instance does not match with the return instance')

data =

# return data variable
return data
38 changes: 36 additions & 2 deletions q02_teams/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q02_teams/build.py
# default imports
from greyatomlib.python_getting_started.q01_read_data.build import read_data
data = read_data()
Expand All @@ -6,6 +7,39 @@
def teams(data=data):

# write your code here
#teams =

teams = data['info']['teams']
return teams

teams(data)
import sys, os
sys.path.append(os.path.join(os.path.dirname(os.curdir)))

from unittest import TestCase
from greyatomlib.python_getting_started.q01_read_data.build import read_data
from q02_teams.build import teams

data = read_data()
ipl_teams = teams(data)




class TestTeams(TestCase):
def test_teams_return_type(self):
self.assertIsInstance(ipl_teams, list,'Expected type does not match the return type')

def test_teams_return_Royal_Challengers(self):
self.assertTrue('Royal Challengers Bangalore' in ipl_teams,'Expected team does not match with the return team')

def test_teams_return_Knight_Riders(self):
self.assertTrue('Kolkata Knight Riders' in ipl_teams,'Expected team does not match with the return team')

def test_teams_return_number_of_teams(self):
self.assertEqual(len(ipl_teams),2,'The expected number of teams does not ')

tt = TestTeams()
tt.test_teams_return_type()
tt.test_teams_return_Royal_Challengers()
tt.test_teams_return_Knight_Riders()
tt.test_teams_return_number_of_teams()

7 changes: 5 additions & 2 deletions q03_first_batsman/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q03_first_batsman/build.py
# Default Imports
from greyatomlib.python_getting_started.q01_read_data.build import read_data
data = read_data()
Expand All @@ -6,8 +7,10 @@
def first_batsman(data=data):

# Write your code here


name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman']
print(name)


return name
first_batsman(data)

11 changes: 9 additions & 2 deletions q04_count/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q04_count/build.py
# Default Imports
from greyatomlib.python_getting_started.q01_read_data.build import read_data
data = read_data()
Expand All @@ -6,6 +7,12 @@
def deliveries_count(data=data):

# Your code here


count = 0;
for balls in data['innings'][0]['1st innings']['deliveries']:

if balls[list(balls.keys())[0]]['batsman'] == 'RT Ponting':
count += 1

return count
deliveries_count(data)

15 changes: 12 additions & 3 deletions q05_runs/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# %load q05_runs/build.py
# Default Imports
from greyatomlib.python_getting_started.q01_read_data.build import read_data
data = read_data()


# Your Solution
def BC_runs(data):

# Write your code here


runs = 0

for balls in data['innings'][0]['1st innings']['deliveries']:
#print(balls[list(balls.keys())[0]])
if balls[list(balls.keys())[0]]['batsman'] == 'BB McCullum':
runs += balls[list(balls.keys())[0]]['runs']['batsman']


return(runs)
BC_runs(data)

13 changes: 11 additions & 2 deletions q06_bowled_players/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q06_bowled_players/build.py
# Default Imports
from greyatomlib.python_getting_started.q01_read_data.build import read_data
data = read_data()
Expand All @@ -6,6 +7,14 @@
def bowled_out(data=data):

# Write your code here


bowled_players = []

for balls in data['innings'][1]['2nd innings']['deliveries']:
if 'wicket' in balls[list(balls.keys())[0]]:
#print(balls[list(balls.keys())[0]]['wicket'])
if balls[list(balls.keys())[0]]['wicket']['kind'] == 'bowled':
bowled_players.append(balls[list(balls.keys())[0]]['wicket']['player_out'])

return bowled_players
bowled_out(data)

16 changes: 15 additions & 1 deletion q07_extras/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q07_extras/build.py
# Default Imports
from greyatomlib.python_getting_started.q01_read_data.build import read_data
data = read_data()
Expand All @@ -6,9 +7,22 @@
def extras_runs(data=data):

# Write your code here
firstInningsExtras = 0
secondInningsExtras = 0
for balls in data['innings'][0]['1st innings']['deliveries']:
#print(balls[list(balls.keys())[0]]['runs']['extras'])
if 'extras' in balls[list(balls.keys())[0]]:
firstInningsExtras += 1

for balls in data['innings'][1]['2nd innings']['deliveries']:
#print(balls[list(balls.keys())[0]]['runs']['extras'])
if 'extras' in balls[list(balls.keys())[0]]:
secondInningsExtras += 1

difference =

difference = secondInningsExtras - firstInningsExtras


return difference
extras_runs(data)