Skip to content

Instantly share code, notes, and snippets.

@mkwatson
Created September 2, 2023 02:57
Show Gist options
  • Save mkwatson/897c97c5f2febf786748b7c8b49a74fc to your computer and use it in GitHub Desktop.
Save mkwatson/897c97c5f2febf786748b7c8b49a74fc to your computer and use it in GitHub Desktop.
def analyze_stats(stats):
insights = ''
if stats['orioles']['batting_average'] > stats['diamondbacks']['batting_average']:
insights += 'The Orioles have a higher batting average than the Diamondbacks. '
else:
insights += 'The Diamondbacks have a higher batting average than the Orioles. '
if stats['orioles']['slugging_percentage'] > stats['diamondbacks']['slugging_percentage']:
insights += 'The Orioles have a higher slugging percentage than the Diamondbacks. '
else:
insights += 'The Diamondbacks have a higher slugging percentage than the Orioles. '
if stats['orioles']['pitching_era'] < stats['diamondbacks']['pitching_era']:
insights += 'The Orioles have a lower pitching ERA than the Diamondbacks. '
else:
insights += 'The Diamondbacks have a lower pitching ERA than the Orioles. '
if stats['orioles']['whip'] < stats['diamondbacks']['whip']:
insights += 'The Orioles have a lower WHIP than the Diamondbacks. '
else:
insights += 'The Diamondbacks have a lower WHIP than the Orioles. '
return insights
stats = {
'orioles': {
'batting_average': .255,
'slugging_percentage': .425,
'pitching_era': 4.04,
'whip': 1.26
},
'diamondbacks': {
'batting_average': .253,
'slugging_percentage': .417,
'pitching_era': 4.63,
'whip': 1.345
}
}
insights = analyze_stats(stats)
insights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment