""" Hello! Somebody has provided some data containg a list of donors, with their names, number of points, and frequency of publication. We need to do a couple of things with it: 1) Output the name of each donor to the console, with their points next to their name, like this: > DFID: 55% 2) Donors publishing quarterly can score a maximum of 95 points - we reduce their points a little by including a multiplier of .95. So, DFID should score only 52.25 points, not 55 points. We need to output that - it should look like this: > DFID scored 55, but scores 52.25 as they publish quarterly 3) You should build upon / adapt the frequency_to_multiplier() function to convert the frequency to some multiplier, i.e. 'monthly' => 1.0 BTW: this is all fake data. """ # The data data = { 'donors': [ { 'name': 'DFID', 'points': 55, 'frequency': 'quarterly'}, { 'name': 'USAID', 'points': 70, 'frequency': 'monthly'}, ]} def frequency_to_multiplier(value): if value == "quarterly": return 0.95 return 1 # Add your code here for donor in data['donors']: multiplier = frequency_to_multiplier(donor.get('frequency')) print "%s scored %s, but scores %s as they publish %s" % (donor['name'], donor['points'], donor['points'] * multiplier, donor['frequency'])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question