Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
559 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | Python (34 exercises) |
Topic ==> | Functions (3 exercises) |
Level ==> | Harder than average |
Subject ==> | Python training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The folder above contains 6 CSV files and one Python program file. Here are the CSV files:
Each of these is a text file containing a list of countries in that continent, together with the country's capital city.
Here's what the Oceania file looks like, for example:
The countries and capital cities of Oceania.
The Python program contains this code, but it needs a bit of work!
def get_contents_of_file(Argument_or_arguments_to_go_here):
# this needs writing!
pass
def get_country_dict(Argument_or_arguments_to_go_here):
# this needs writing!
pass
def print_results(Argument_or_arguments_to_go_here):
# this needs writing!
pass
# choose continent to show data for
continent_name = "Oceania"
# get text from file for given continent name
country_list = get_contents_of_file(continent_name)
# from this extract a list of countries and cities
countries = get_country_dict(country_list)
# list them out
print_results(continent_name,countries)
Your task is to write the functions so that when you run the program you get this (if you set the continent name to Oceania, for example):
Try running your program for a couple of different continents to check it works.
A final thought: what happens if you try the continent name as Antarctica? Can you make your program do something sensible in this case?
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.