Before you attempt this activity, it is best that you review lecture video two from week seven. You can find the video and slides on the module page.
For this activity you will be using the integrated development environment recommended by the module leader. If you need to set up your development environment, it is recommended that you check out the instructions from activity four of week one.
Are You Struggling?
If you have trouble with any of the tasks or want to check your answers are correct, then please make yourself known to a member of staff.
For this task you are required to implement a class called Student. The class should consist of the following variables:
Variable Name | Value |
---|---|
name | Ian1 |
age | 331 |
startDate | 13/09/2022 |
course | Ethical Hacking and Cyber Security |
degreeClassification | ["BSc", "MSci, "MScR", "PhD"]2 |
1: This can be any value you wish. 2: Pick one of the items from the list, i.e. BSc.
The class will have a constructor method to populate the variables. If the degreeClassification value does not match one of those provided in the table above, then an exception should be raised to the user highlighting their mistake. The wording of the exception to be thrown should be:
degreeClassification is not a valid classification, use either: BSc, MSci, MScR or PhD
For this task, you need to create a function called greeting within class student that provides a default greeting. The greeting should say the following:
Hello name and welcome to course. You are currently studying for a degreeClassification.
Where the degree specification should be worded in its entirety, with the initialism next to it in brackets. See the table below for more information.
Initialism | Definition |
---|---|
BSc | Bachelor of Science |
MSci | Master of Science |
MScR | Master of Science by Research |
PhD | Doctor of Philosophy |
For this task, you are expected to create a function called export_details which will export the details of a given student to a dictionary.
For this task you need to ensure that you use the variable names as a key for the dictionary. For example:
student1 = {
"name": "Ian",
"age": 32,
"start_date": "13/09/2021",
"course": "Ethical Hacking",
"degree_classification": "BSc"
}
For this task, you are expected to create a function called export_all which will export the details of all students that have been created. The details will be exported to a CSV file which will consist of a header detailing the information that is held. For example:
name,age,start_date,course,degree_classification
Ian,32,13/09/2021,Ethical Hacking,BSc
Terry,UNKNOWN,13/09/2021,Ethical Hacking,MSc
James,35,13/09/2021,Ethical Hacking,PhD
For this function, it is not expected to be within the class student and you can use the function created in the previous task (exporting to a dictionary) to aid in this solution.
Secondly, the function will require a list to be passed through that contains all of the student details. This will then be written to a CSV file using the csv module.