diff --git a/myfile.txt b/myfile.txt new file mode 100644 index 00000000..e69de29b diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..30e802c5 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,21 @@ +# %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 - - data = - + + with open('./data/ipl_match.yaml') as file : + + data = yaml.load(file) + # return data variable return data + +d = read_data() +d + + diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..c286bfb4 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,11 +1,15 @@ +# %load q02_teams/build.py # default imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() - # solution def teams(data=data): - # write your code here - #teams = + # write your code here + teams = data['info']['teams'] return teams + + + + diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..3d3a2ce0 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,16 @@ def first_batsman(data=data): # Write your code here - + + name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] return name + + + + + + + diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..b43bfda3 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,19 @@ +# %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): + i=0 + deliveries = data['innings'][0]['1st innings']['deliveries'] + for delivery in deliveries: + for delivery_number, delivery_info in delivery.items(): + if delivery_info['batsman'] == 'RT Ponting': + i += 1 - # Your code here - - return count + return i + + + diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..2971cfbc 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,19 @@ def BC_runs(data): # Write your code here + deliveries = data['innings'][0]['1st innings']['deliveries'] + + runs = 0 + + for i in deliveries: + for key in i: + run_var = i[key] + if run_var['batsman'] == 'BB McCullum': + runs += run_var['runs']['batsman'] + + return(runs) + +b = BC_runs(data) +b - return(runs) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..94759bb0 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,39 @@ def bowled_out(data=data): # Write your code here + bowled_players = [] + + return bowled_players + +# %load q06_bowled_players/build.py +# Default Imports +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() + +# Your Solution +def bowled_out(data=data): + + # Write your code here + bowled_players = [] + deliveries = data['innings'][1]['2nd innings']['deliveries'] + + for delivery in deliveries: + + for key in delivery: + + run_variable = delivery[key] + + if 'wicket' in run_variable and run_variable['wicket']['kind'] == 'bowled': + + bowled_players.append(run_variable['batsman']) + + + + + return bowled_players + + + diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..39a9155e 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,3 +1,34 @@ +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() + +def extras_runs(data=data): + deliveries1 = data['innings'][0]['1st innings']['deliveries'] + extras1=[] + + for delivery1 in deliveries1: + + for key in delivery1: + + extras1.append(delivery1[key]['runs']['extras']) + + deliveries2 = data['innings'][1]['2nd innings']['deliveries'] + + extras2=[] + + for delivery2 in deliveries2: + + for key in delivery2: + + extras2.append(delivery2[key]['runs']['extras']) + + difference=sum(extras2)-sum(extras1) + + return difference + +e = extras_runs(data=data) +e + +# %load q07_extras/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,9 +37,35 @@ def extras_runs(data=data): # Write your code here + first_innings = 0 + deliveries1 = data['innings'][0]['1st innings']['deliveries'] + + for i in deliveries1: + for key in i: + run_var = i[key] + if 'extras' in run_var: + for key1 in run_var['extras']: + first_innings += 1 + - difference = + second_innings = 0 + deliveries2 = data['innings'][1]['2nd innings']['deliveries'] + for i in deliveries2: + for key in i: + run_var = i[key] + if 'extras' in run_var: + for key2 in run_var['extras']: + second_innings += 1 + + + difference = (second_innings - first_innings) + return difference + +extras_runs(data=data) + + +