A Record allows us to define a structure that can contain one or more variables (attributes) with each one potentially having a different data type.
As we are using Python, we will create a record by defining a class. The basic structure of a class can be seen below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class MySubjects(object): # this function creates the object and initialises any attributes def __init__(self, subjectName, noOfPeriods, teacherName): self.subjectName = subjectName self.numberOfPeriods = noOfPeriods self.teacherName = teacherName # when called this function (method) will return the value of subject name def getSubjectName(self): return self.subjectName # when called this function (method) will set the attribute sunjectName to the value of the parameter passed def setSubjectName(self, subjectName): self.subjectName = subjectName
To create an object of type ‘MySubjects’ we do the following code:
subjects = MySubjects(subjectName, noOfPeriods, teacherName)
Task 1: Copy the program above and create three objects of ‘MySubjects’ and display all of the subject names by calling the appropriate method. Create get and set methods for the other attributes.
Task 2: Change the above program so that it can store a list of five subjects. You will get the user to enter five subjects and store them in a list (array).
Task 3: Make two more useful improvements to the program.
Please complete the questions from the link below:
Answers in your jotter(back) or word document.
This should be completed by: 13/06/2014
In order to complete these series of mini-tasks you will first need to complete sections 1, 2, 3, 4 and 5.
Read the following links too:
– Quiz games and if statements.
1: Play withing Strings.
– The user of your program should enter their first name, surname and date of birth.
– The program should then display the length of each piece of data and convert it to uppercase and lowercase.
2: You must create a speed, distance and time calculator.
Help on creating a calculator can be found here.
– The user must first choose whether they want to calculate S, D or T.
– The user should then be prompted to enter in the relevant information for the chosen calculation.
– The program should then calculate the answer and display an appropriate message. You must use the technique from ‘Strings and Console Ouput – sub-section 15’.
– Your program should be timestamped (dd/mm/yyyy : hh-mm-ss).
3. Complete the above problem in Scratch!!!
3: A Mathematical Calculator (CHALLENGE)
– You must create a calculator that can perform the basic operations, powers and roots (square) and percentages.
At code academy you are given the option to link your account to google, facebook and yahoo. During your National 5 course, it is preferred that you do not link to any social networking account. After the course has been completed and you have sat exam then by all means link your account.
Here at computingdhs.co.uk you will find links to relevant websites and resources. Everything will be posted on the homepage, where you can access it easily.