Question: I am totally lost on this Python Coding assignment. It has three parts, a, b and c. I go to create A which is creating

I am totally lost on this Python Coding assignment. It has three parts, a, b and c. I go to create A which is creating a class and needing to use a UN.txt file to create a pickled binary file named nationsDict.dat and saving the class in a file named nation.py - I get the below error with my code in the first step. Please help!

I am totally lost on this Python Coding assignment. It has three

parts, a, b and c. I go to create A which is

creating a class and needing to use a UN.txt file to create

Chapter 7 Programming Projects 1. United Nations The file UN.txt gives data about the 193 members of the United Nations. Each line of the file contains four pieces of data about a - country-name, continent, population (in millions), and land area (in square miles). Some lines of the file are Canada, North America, 34.8,3855000 France, Europe, 66.3,211209 New Zealand, Australia/Oceania, 4.4,103738 Nigeria, Africa, 177.2,356669 Pakistan, Asia, 196.2,310403 Peru, South America, 30.1,496226 a. Create a class named Nation with four instance variables to hold the data for a country and a method named popDensity that calculates the population density of the country. Write a program that uses the class to create a dictionary of 193 items, where each item of the dictionary has the form name of a country: Natian object for that country Use the file UN.txt to create the dictionary, and save the dictionary in a pickled binary file named nationsDict.dat. Also, save the class Nation in a file named nation.py. nm non class Nation: def __init_(self, country="", continent="", population=0.0, area=0): self._country = country self._continent = continent self._population = population self._area = area self._popDensity = (1000000*float(self._population)) / int(float(self._area)) def setCountry(self, country): self._country = country def setContinent(self, continent): self._continent = continent def set Population(self, population): self._population = population def setArea(self, area): self._area = area def getCountry(self): return self._country def getContinent(self): return self._continent 27- def get Population(self): return self._population def getArea(self): return self._area 33 - def popDensity (self): self._popDensity = (1000000*float(self._population)) / int(float(self._area)) | return self._popDensity 37 - with open('UN.txt', 'r') as f: out=f.read() out-out.split(' ') cntry_dict={} 41 - for inp in out: inp_cpy=inp.split( ') cntry_dictinp_cpy[O]]= Nation (inp_cpy[O],inp_cpy[1],inp_cpy[2], inp_cpy(3]) 44 45 import pickle 46 47 - with open('nationsDict.dat', 'wb') as handle: 48 pickle.dump (cntry_dict, handle, protocol=pickle.HIGHEST_PROTOCOL) 49 50- with open('nationsDict.dat', 'rb') as handle: cntry_dict_copy = pickle.load(handle) 53 out=input('Enter a Country:') print(""" 55 Continent: %s 56 Population: %s 57 Area: %s square miles"!" % (cntry dict copy out). continent, cntry dict copy out). population, cntry dict copy outl. area)) ZeroDivisionError: float division by zero Chapter 7 Programming Projects 1. United Nations The file UN.txt gives data about the 193 members of the United Nations. Each line of the file contains four pieces of data about a - country-name, continent, population (in millions), and land area (in square miles). Some lines of the file are Canada, North America, 34.8,3855000 France, Europe, 66.3,211209 New Zealand, Australia/Oceania, 4.4,103738 Nigeria, Africa, 177.2,356669 Pakistan, Asia, 196.2,310403 Peru, South America, 30.1,496226 a. Create a class named Nation with four instance variables to hold the data for a country and a method named popDensity that calculates the population density of the country. Write a program that uses the class to create a dictionary of 193 items, where each item of the dictionary has the form name of a country: Natian object for that country Use the file UN.txt to create the dictionary, and save the dictionary in a pickled binary file named nationsDict.dat. Also, save the class Nation in a file named nation.py. nm non class Nation: def __init_(self, country="", continent="", population=0.0, area=0): self._country = country self._continent = continent self._population = population self._area = area self._popDensity = (1000000*float(self._population)) / int(float(self._area)) def setCountry(self, country): self._country = country def setContinent(self, continent): self._continent = continent def set Population(self, population): self._population = population def setArea(self, area): self._area = area def getCountry(self): return self._country def getContinent(self): return self._continent 27- def get Population(self): return self._population def getArea(self): return self._area 33 - def popDensity (self): self._popDensity = (1000000*float(self._population)) / int(float(self._area)) | return self._popDensity 37 - with open('UN.txt', 'r') as f: out=f.read() out-out.split(' ') cntry_dict={} 41 - for inp in out: inp_cpy=inp.split( ') cntry_dictinp_cpy[O]]= Nation (inp_cpy[O],inp_cpy[1],inp_cpy[2], inp_cpy(3]) 44 45 import pickle 46 47 - with open('nationsDict.dat', 'wb') as handle: 48 pickle.dump (cntry_dict, handle, protocol=pickle.HIGHEST_PROTOCOL) 49 50- with open('nationsDict.dat', 'rb') as handle: cntry_dict_copy = pickle.load(handle) 53 out=input('Enter a Country:') print(""" 55 Continent: %s 56 Population: %s 57 Area: %s square miles"!" % (cntry dict copy out). continent, cntry dict copy out). population, cntry dict copy outl. area)) ZeroDivisionError: float division by zero

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!