Lab Objectives: Classes
Instructions: Upload your solutions as a single .zip file to the Lab07 assignment on Moodle before the end of your lab session. Use the following naming convention:
SS_Lab07_Surname_FirstName.zip where SS is the section number 01, 02, 03, etc.
- Write a class called Person (py) that represents a typical Person object.
- The class will store the following attributes:
- Name
- Age
- Gender
- Location
- Your class should have an init() method that takes the values of all four attributes as parameters.
- Your class should have the following methods:
- Name: returns the value of the attribute
- Age: returns the value of the attribute
- Gender: returns the value of the attribute
- Location: returns the value of the attribute + updates value of the attribute
- The class will store the following attributes:
- You should also write IncreaseAge() method for increasing the persons age.
- In addition to the accessor/mutator methods, your class should define a __repr__ method that returns the string information about the Person in the following format, where
gulsah is the name, 21 is the age, and female is the gender and ankara location):
Name : gulsah Age : 21
Gender : female
Location: ankara
- Create a script that does the following:
- Define method getByLocation(): takes a list of Persons as a parameter and returns the list of Persons who have the location passed as a parameter.
- Define method getByGender(): takes a list of Persons as a parameter returns the list of Persons who have the gender passed as a parameter.
- Read data from the file input.txt and creates a list of People using data from the file.
- Using the list and the functions defined in part a and b, print all the females in Ankara.
Sample Run:
Printing Females in Ankara
Name: gizem
Age: 21
Gender: female
Location: ankara
Name: gulsah
Age: 21
Gender: female
Location: ankara Output will appear as follows:
Reviews
There are no reviews yet.