Kings & Queens of England

Portrait of Henry VIII
Portrait of Henry VIII

There have been 66 monarchs of England and Britain spread over a period of 1500 years.

For this challenge you will use a text file listing all of these monarchs in chronological order. You will then write a Python program to prompt the user to enter a year (between 757 and 2017) and your program will look up for the name of the monarch of England at the given date.

To complete this challenge you will need to read more about how to read through a CSV file.

The text file we will use contains one line per monarch. On each line it stores the year the reign started, the year it ended and the name of the monarch as follows:

StartYear,EndYear,Name
TextFileMonarchs-of-England.csv

Complete the Code


Testing


Once you have completed the code check that it produces the expected output by performing the following tests:

Test # Input Values Expected Output Actual Output
#1 1192 Richard I
#2 1345 Edward III
#3 1042 Harthacanut
Edward the Confessor
#4 1547 Henry VIII
Edward VI
#5 1016 Ethelred II the Unready
Edmund lronside
Cnut (Canute)
#6 512 Not Found

Extension Task:


Tweak the output of your program so that when giving the name of the monarch matching the year entered, your program also mentions who were the previous monarch and the next monarch.

For instance the output of the program could be:

In 1192, the monarch of England was Richard I. Their predecessor was Henry II up until 1189 and their successor was John whose reign started in 1199.

Share Button
Posted in Computer Science, Python - Intermediate, Python Challenges Tagged with: , ,
One comment on “Kings & Queens of England
  1. Vinny999 says:

    Great Challenge!

Our Latest Book