Question: Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. Specifically, your

Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as parameters a year and a category, and returns a sorted list of the surnames for the winner(s) in that category for that year (up to three people can share the prize). The year will be a string (e.g. "1975"), not a number. The categories are: "chemistry", "economics", "literature", "peace", "physics", and "medicine". The JSON file will be named nobels.json and will be provided - you do not need to submit it.

For example, your class could be used like this:

The file must be named: NobelData.py

I'm stuck on this problem. This is what I have so far but I am getting errors.

import json class NobelData: def __init__(self): response = json.get("http://api.nobelprize.org/v1/prize.json") self.data = response.json() def search_nobel(self, year, category): a = len(self.data['prizes']) winners = [] for i in range(0, a): if (self.data['prizes'][i]['year']==year and self.data['prizes'][i]['category']==category): winners = self.data['prizes'][i]['laureates'] break b = len(winners) w_sur = [] for i in range(0, b): w_sur.append(winners[i]['surnames']) w_sur.sort() return w_sur nd = NobelData() w_sur = nd.search_nobel("2001", "economics") print(w_sur) surnames = ["chemistry", 'economics', 'literature', 'peace', 'physics', 'medicine'] 
nd = NobelData() nd.search_nobel("2001", "economics") 

"http://api.nobelprize.org/v1/prize.json"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!