Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the document catalogue.py, likely including like .py files for the same homework, in the def saveCountryCatalogue(self,fname): why are 2 instance variables, _countrySorted and _sortName,

In the document catalogue.py, likely including like .py files for the same homework, in the def saveCountryCatalogue(self,fname): why are 2 instance variables, _countrySorted and _sortName, created if they serve no purpose in the function? _sortName is used however it appears to be just as a counter even though we are supposed to sort the data it is never stored and thus useless.

image text in transcribed
#saving the data def saveCountrycatalogue (self, fname ): try : countrySorted = {} sortName = for name in self._countrycat: sortName . append (name ) #sort through the name sortName . sort ( ) #loop through the names, then find the country and storing the information in the sorted country dictionry #create a new file and write data to it _newCountryFile = open(fname, "w") _newCountryFile. write("Country |Continent | Population |Area" ) _newCountryFile .write("\\") for c in _sortName: if c in self._countrycat: name = c pop = str (self ._countrycat[c] . getpopulation( ) ) area = str (self._countrycat[c]. getArea( ) ) cont = self._countrycat [c] . getcontinent ( ) #print (name + "|" + cont + "|" + pop + "|" + area) _newCountryFile . write(name + "|" + cont + "|" + pop + "|" + area) newCountryFile. write("\\") continue newCountryFile. close ( ) return len(_countrysorted) except : return - 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

Branding strategy: building strong brands

Answered: 1 week ago