Question: #Problem 1: #Use the file transactions.csv. (Download the file here.) Write thefunction called getCountries() that takes 0 arguments. #The function should open the transactions file

#Problem 1:

#Use the file transactions.csv. (Download the file here.) Write thefunction called getCountries() that takes 0 arguments.

#The function should open the transactions file and determine all of the unique countries in that file.

#i.e. There should not be any repeated countries. Your function should return a list of the countries.

#The list should be sorted.

#Have exception handling code in case the file cold not be found.

#That is, catch a FileNotFoundError.

#If this exception is generated, your function should simply print an error to the screen (e.g. " Unable to open the file. ") and then terminate.

#Remember that only the relevant code should be placed inside the try block.

#That is, do not place too much code unrelated to the part you are worried about inside a given try block.

PYTHON

The code is supposed to look like this as an outcome

>>> print(getCountries()) ['Australia', 'Belgium', 'Canada', 'Denmark', 'Finland', 'France', 'India', 'Ireland', 'Israel', 'Italy', 'Luxembourg', 'Netherlands', 'Norway', 'South Africa', 'Sweden', 'Switzerland', 'United Kingdom', 'United States'] 

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 Programming Questions!