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...
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.
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...
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
The programming language is Python Instructions: Create a function that will delete a node in a...
The programming language is Python Instructions: Create a function that will delete a node in a Linked List based on position number. On below example, if you want to delete position #2, it will remove the Banana (arrangement of nodes below is Apple, Banana, Cherry, Grapes, Orange). myLinkedList = LinkedList() myLinkedList.append("Banana") myLinkedList.append("Cherry") myLinkedList.append("Grapes") myLinkedList.append("Orange") myLinkedList.prepend("Apple") myLinkedList.deleteByPositionNum(2) node = myLinkedList.head while node: print(node.value, " ") node = node.next_node You may start with the function head: def deleteByPositionNum(self, positionNum):
in python programming language, please include the proper identation This homework will allow you to demonstrate...
in python programming language, please include the proper identation This homework will allow you to demonstrate understanding and engagement with the following topics: graph representations object oriented programming graph processing,such as finding shortest paths and finding tree traversals Your task is to implement a Graph class. The edges in the graph are undirected, but you must implement an Edge class. In addition, you will have a Graph class, and a Node class. You can choose to implement graphs with any...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Python Assignment You will be writing an inventory system that is backed by JSON data and...
Python Assignment You will be writing an inventory system that is backed by JSON data and will be working with a starter file that contains a JSON string. The code you write will need to follow the following guidelines. The what You’re at work one day and your boss asks you about that fancy programming language you’ve been learning, Python. She asks you if you can use it to read JSON data from a supplier and build an inventory. “Of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT