diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..c38c9dbd 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,9 @@ import yaml def read_data(): + with open('./data/ipl_match.yaml') as f: + data = yaml.load(f) + return data + +data - # import the csv file into `data` variable - # You can use this path to access the CSV file: '../data/ipl_match.yaml' - # Write your code here - - data = - - # return data variable - return data diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..9891c69f 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -2,10 +2,10 @@ from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() -# solution def teams(data=data): + teams = data['info']['teams'] + return teams + +info = teams(data) - # write your code here - #teams = - return teams diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..8d8b888b 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,13 +1,17 @@ +# %load q03_first_batsman/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # Your Solution def first_batsman(data=data): + + name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] - # Write your code here + return name + +batsman = first_batsman(data) - return name diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..05c03512 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -2,10 +2,26 @@ 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 - + + count = 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': + count += 1 return count + +ricky= deliveries_count(data) +print(ricky) + + +i=8 + +(int(8/6)+((8%6)+1)/10.0) +data['innings'][0]['1st innings']['deliveries'][8] +int(8/6) + + + diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..63fb8319 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() @@ -5,8 +6,27 @@ # Your Solution def BC_runs(data): - - # Write your code here + runs = 0 + deliveries = data['innings'][0]['1st innings']['deliveries'] + for delivery in deliveries: + for delivery_number, delivery_info in delivery.items(): + if delivery_info['batsman'] == 'BB McCullum': + runs+= delivery_info['runs']['batsman'] + return(runs) + +BM=BC_runs(data) +print(BM) + +# %load q05_runs/build.py +# Default Imports +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() +deliveries = data['innings'][0]['1st innings']['deliveries'][0][0.1]['runs'] +deliveries +deliveries = data['innings'][0]['1st innings']['deliveries'] +deliveries + + diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..8283a3a3 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,11 +1,25 @@ +# %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 +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() + def bowled_out(data=data): + bowled_players = [] + deliveries = data['innings'][1]['2nd innings']['deliveries'] + for delivery in deliveries: + for delivery_number, delivery_info in delivery.items(): + if 'wicket' in delivery_info and delivery_info['wicket']['kind'] == 'bowled': + bowled_players.append(delivery_info['wicket']['player_out']) + + return bowled_players + +bowled= bowled_out(data) +print(bowled) + - # Write your code here - return bowled_players diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..022a7e1e 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,14 +1,46 @@ +# %load q07_extras/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() - +diffrence=0 # Your Solution def extras_runs(data=data): + count2=0 + deliveries=data['innings'][1]['2nd innings']['deliveries'] + for delivery in deliveries: + for delivery_number, delivery_info in delivery.items(): + if 'extras' in delivery_info: + count2=count2+1 - # Write your code here + deliveries=data['innings'][0]['1st innings']['deliveries'] + count1=0 + for delivery in deliveries: + for delivery_number, delivery_info in delivery.items(): + if 'extras' in delivery_info: + count1=count1+1 + + difference= count2-count1 + return difference +print(extras_runs(data)) +# %load q07_extras/build.py +# Default Imports +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() +count2=0 +deliveries=data['innings'][1]['2nd innings']['deliveries'] +for delivery in deliveries: + for delivery_number, delivery_info in delivery.items(): + if 'extras' in delivery_info: + count2=count2+1 - difference = +deliveries=data['innings'][0]['1st innings']['deliveries'] +count1=0 +for delivery in deliveries: + for delivery_number, delivery_info in delivery.items(): + if 'extras' in delivery_info: + count1=count1+1 + +print(count2-count1) - return difference