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 ==> | Sequences (5 exercises) |
Level ==> | Relatively easy |
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.
Open the Python code file in the above folder - it should contain a list of British Prime Ministers from the start of the 21st century up to Rushi Sunak:
The list of Prime Ministers contains one extra name!
Set a variable to hold the number of items in the sequence (use the len function), then use this as an index to change the last item in your sequence to your name.
Note that this is impossible as things stand, because you're looking at an immutable sequence - you'll need to convert the tuple to a list before you can change anything in it.
Add a command to sort your list into alphabetical order.
Loop over the items in this (now sorted) list, writing out for each Prime MInister their name and their position in the list:
Your order may be slightly differnent, depending on where your name comes in the alphabet.
Here's the syntax of the enumerate function, as a reminder:
The syntax of the enumarate function, which returns an extra varaible for each item giving its order within the list.
When you've finished, save your program as Tupling the PM and then close it down.
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.