Question

In: Computer Science

Programming language is in python 3 For this project, you will import the json module. Write...

Programming language is in python 3

For this project, you will import the json module.

Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. 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 (in normal English dictionary order) 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. Any data members of the NobelData class must be private.

For example, your class could be used like this:

nd = NobelData()
nd.search_nobel("2001", "economics")

The file must be named: NobelData.p

Solutions

Expert Solution

NOTE:- IN CASE OF ANY QUERY FEEL FREE TO ASK IN COMMENT ANYTIME.....HAPPY LEARNING......

PYTHON CODE:-

import requests

#Implementation of NobelData class

class NobelData:

    #Implementation of init

    def __init__(self):

        responseObject = requests.get("http://api.nobelprize.org/v1/prize.json")

        #load json format data

        self.data = responseObject.json()

     

    #Implementation of search_nobel method

    def search_nobel(self,year,category):

        #Declare n and store the length of self.data['prizes']

        lengthofPrizes= len(self.data['prizes'])

        #Declare winners as type of list

        winners=[]

        #Declare surnamesofthewinners as type of list

        surnamesofthewinners=[]

        #Iterate loop

        for each in range(0,lengthofPrizes):

          #check self.data['prizes'][each]['year'] is equal to year

          #and check self.data['prizes'][each]['category'] is equal to category

            if(self.data['prizes'][each]['year']==year and self.data['prizes'][each]['category']==category):

              #assign self.data['prizes'][each]['laureates'] to winners

                winners=self.data['prizes'][each]['laureates']

                break

        #caclulate the length of winners and store in lengthofWinners

        lengthofWinners=len(winners)

        #Iterate the loop

        for each in range(0,lengthofWinners):

          #append the winners[each]['surname'] to surnamesofthewinners

            surnamesofthewinners.append(winners[each]['surname'])

           

        #sort the surnamesofthewinners

        surnamesofthewinners.sort()

        return surnamesofthewinners

#Declare an object for NobelData

nd = NobelData()

#call serach_nobel method

nd.search_nobel("2001", "economics")

#Display statement

print(nd.search_nobel("2001", "economics"))

--------------I hope my answer met all your requirements......Please upvote..Thank You----------------


Related Solutions

Programming language is python 3 For this project, you will import the json module. Write a...
Programming language is python 3 For this project, you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The...
This lab problem demonstrates the use of import module. The Python programming language has many strengths,...
This lab problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules. We have given you some incomplete code; note that the very first line of that code contains an import statement as follows: import math This statement enables your program to use a...
Python Language: Similar to Project 3, write a program that loops a number from 1 to...
Python Language: Similar to Project 3, write a program that loops a number from 1 to 10 thousand and keeps updating a count variable according to these rules: if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if none of the above conditions match for the number, increase count by the number. Before the loop begins,...
Programming language in Python Suppose, for Jane, n1 = 3, n2 = 4, and n3 =...
Programming language in Python Suppose, for Jane, n1 = 3, n2 = 4, and n3 = 5. Also suppose, Jane iterates the number from 1 to 15. At the beginning, Jane sets count to 0, and then proceeds iterating the number from 1 to 15 and for each iteration does the following: for 1, count is increased by 1 because it is not divisible by 3, 4, and 5; count is now: 1 for 2, count is increased by 2...
Python programming problem! Suppose that there is a json file called data from the desktop. I...
Python programming problem! Suppose that there is a json file called data from the desktop. I want to print the value with the key of "year" and "country". Json file below: { "A":{ "year":11, "grade":A, "country":America}, "B":{ "year":18, "grade":C, "country":England}, "C":{ "year":19, "grade":B, "country":China},} I want a code that I can only replace the name of key from year to grade and the code could be work.
Module and Import For these 3 problems, -You are writing a function to calculate a formula...
Module and Import For these 3 problems, -You are writing a function to calculate a formula in the module. -You are going to import the modules to the main. -Write 3 more functions in the main -Don't do any formula calculation in the main just use module functions and return your result. -Call each main function twice to test the provided values. 1. Meter to Feet and Inches One meter equals 39.37 inches and 1 foot equals 12 inches. Write...
The Programming Language is C++ Objective: The purpose of this project is to expose you to:...
The Programming Language is C++ Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd Binary numbers // 00000000, 0101, 111111, etc. Show: Finite Automaton Definition, Graph, Table
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned integer numbers // 123, 007, 4567890, etc. Show: Finite Automaton Definition, Graph, Table.
PYTHON Suppose you need to import a single class named GeneTools from a module named bioinformatics,...
PYTHON Suppose you need to import a single class named GeneTools from a module named bioinformatics, in Python. Which of the following represents the correct use of an import statement? import GeneTools from bioinformatics from bioinformatics import GeneTools from bioinformatics import * import GeneTools
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT