Pyhton - ONE TO ONE RELATIONSHIP
P11 / ONE TO ONE RELATIONSHIP – 2
P11 / One to One Relationship – 2
Create a class named Address with the following private_attributes
__street
__city
__state
Include a constructor
__init__(self, street, city, state)
Include a method
__str__(self)
This method returns a string corresponding to Address details in the format specified
in the sample output.
Include @property decorator for state
Create a class named Person with the following private_attributes
__name
__age
__address (of type Address)
Include a constructor
__init__(self, name, age, address)
Include a method
__str__(self)
This method returns a string corresponding to Person details in the format specified
in the sample output.
Include @property decorator for name
Include @property decorator for address
Create objects of the above classes and test them.
Input and Output Format:
Refer Sample Input and Output for formatting specifications.
Sample Input and Output 1:
[All text in bold corresponds to input and the rest corresponds to output]
Enter name
Mahirl
Enter age
10
Enter address
Enter street
LMC Street
Enter city
Salem
Enter state
Tamilnadu
Do you want to add another person? Type yes/no
yes
Enter name
Priya
Enter age
20
Enter address
Enter street
Gandhi Street
Enter city
Coimbatore
Enter state
Tamilnadu
Do you want to add another person? Type yes/no
yes
Enter name
Sita
Enter age
30
Enter address
Enter street
Amphi Street
Enter city
Bangalore
Enter state
Karnataka
Do you want to add another person? Type yes/no
no
Search By State
Enter state
Tamilnadu
List of persons from Tamilnadu
['Mahirl', 'Priya']
Sample Input and Output 2:
Enter name
Rathish
Enter age
25
Enter address
Enter street
Jagan street
Enter city
Coimbatore
Enter state
Tamilnadu
Do you want to add another person? Type yes/no
no
Search By State
Enter state
Kerala
List of persons from Kerala
[]
Comments
Post a Comment