Starting from:

$30

CS115-Lab 7 Solved

1.      Write a class called  Person  (Person.py) that represents a typical Person object.

a.      The class will store the following attributes:

•   Name 

•   Age 

•   Gender

•   Location

b.      Your class should have an init() method that takes the values of all four attributes as parameters.

c.      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

 

d.      You should also write IncreaseAge() method for increasing the person’s age.

e.      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
 

                

2.      Create a script that does the following: 

a.      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.

b.      Define method getByGender(): takes a list of Persons as a parameter returns the list of Persons who have the gender passed as a parameter.

c.      Read data from the file input.txt and creates a list of People using data from the file.

d.      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:

More products