diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..83e84cc3 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,23 @@ +# %load q01_read_data/build.py import yaml def read_data(): - # import the csv file into `data` variable - # You can use this path to access the CSV file: '../data/ipl_match.yaml' + # import the csv file into variable + #ta You can use this path to access the CSV file: '../data/ipl_match.yaml' # Write your code here - - data = - + + with open('./data/ipl_match.yaml','r') as file_obj: + data = yaml.load(file_obj) # to load content of file + #print(type(data)) + print(data) + # return data variable return data +read_data() + + + + + + diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..c62c3b9b 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -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() @@ -6,6 +7,9 @@ def teams(data=data): # write your code here - #teams = - + teams = data['info']['teams'] + print(type(teams)) return teams +teams() + + diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..0ce755bc 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -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() @@ -6,8 +7,13 @@ def first_batsman(data=data): # Write your code here + name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] + print(type(name)) + return name +name = first_batsman() +print(name) + - return name diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..5a5a6bc1 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,32 @@ +# %load q04_count/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() + # Your Solution Here def deliveries_count(data=data): # Your code here + number_of_bowl = len(data['innings'][0]['1st innings']['deliveries']) #no of ball in 1st innings + count = 0 #to count the number of ball RT pointing played + + for ball_no in range(number_of_bowl): #loop over each ball + #return dictionary of particular ball no + di = data['innings'][0]['1st innings']['deliveries'][ball_no] + + for ke in di.keys(): + if data['innings'][0]['1st innings']['deliveries'][ball_no][ke]['batsman'] == 'RT Ponting': + count = count + 1 + print(type(count)) return count + +deliveries_count() + + + + + + diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..2ce99632 100644 --- a/q05_runs/build.py +++ b/q05_runs/build.py @@ -1,3 +1,4 @@ +# %load q05_runs/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -7,6 +8,22 @@ def BC_runs(data): # Write your code here - + number_of_bowl = len(data['innings'][0]['1st innings']['deliveries']) #no of ball in 1st innings + runs = 0 #to count the number of runs scored by Brendon maCcullum + + for ball_no in range(number_of_bowl): #loop over each ball + + #return dictionary of particular ball no + di = data['innings'][0]['1st innings']['deliveries'][ball_no] + + for ke in di.keys(): + if data['innings'][0]['1st innings']['deliveries'][ball_no][ke]['batsman'] == 'BB McCullum': + + runs = runs + data['innings'][0]['1st innings']['deliveries'][ball_no][ke]['runs']['batsman'] + return(runs) + +BC_runs(data) + + diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..7a59f4c4 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -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() @@ -6,6 +7,29 @@ def bowled_out(data=data): # Write your code here - + + bowled_players = [] #empty list for storing bowled players + + #total number of ball played in whole match + number_of_balls_played = len(data['innings'][1]['2nd innings']['deliveries']) + + for ball_number in range(number_of_balls_played): + + #dictionary of each ball + di = data['innings'][1]['2nd innings']['deliveries'][ball_number] + + for ke in di.keys(): # to get inside the ball details + + # check whether player out or not in particular ball + if ( 'wicket' in data['innings'][1]['2nd innings']['deliveries'][ball_number][ke].keys()): + + # check wicket get was bowled + if data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]['wicket']['kind'] == 'bowled': + + bowled_players.append(data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]['wicket']['player_out']) return bowled_players + +bowled_out(data) + + diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..9d1d41d5 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -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() @@ -6,9 +7,45 @@ def extras_runs(data=data): # Write your code here + #for Ist innings + + list_of_extra_runs_in_1st_innings = [] + number_of_balls_played = len(data['innings'][0]['1st innings']['deliveries']) + + + for ball_number in range(number_of_balls_played): + + di = data['innings'][0]['1st innings']['deliveries'][ball_number] + + for ke in di.keys(): + + if 'extras' in data['innings'][0]['1st innings']['deliveries'][ball_number][ke]: + list_of_extra_runs_in_1st_innings.append(data['innings'][0]['1st innings']['deliveries'][ball_number][ke]['extras']) + + + # for 2nd innings + + list_of_extra_runs_in_2nd_innings = [] + number_of_balls_played = len(data['innings'][1]['2nd innings']['deliveries']) + + + for ball_number in range(number_of_balls_played): + + di = data['innings'][1]['2nd innings']['deliveries'][ball_number] + + for ke in di.keys(): + + if 'extras' in data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]: + list_of_extra_runs_in_2nd_innings.append(data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]['extras']) + + + + + + difference = len(list_of_extra_runs_in_2nd_innings) - len (list_of_extra_runs_in_1st_innings) + return difference - difference = +extras_runs() - return difference