Skip to content

Commit 099d936

Browse files
committed
Add an address parameter to the Person class __init__ and stored it as self.address
1 parent 1f45822 commit 099d936

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
class Person:
2-
def __init__(self, name: str, age: int, preferred_operating_system: str):
2+
def __init__(self, name: str, age: int, preferred_operating_system: str, address: str):
33
self.name = name
44
self.age = age
55
self.preferred_operating_system = preferred_operating_system
6+
self.address = address
67

78
def is_adult(self) -> bool:
89
return self.age >= 18
910

1011

11-
imran = Person("Imran", 22, "Ubuntu")
12+
imran = Person("Imran", 22, "Ubuntu", "123 Main St")
1213
print(imran.name)
13-
# print(imran.address) # Error: address is not an attribute
14+
print(imran.address)
1415
print(imran.is_adult())
1516

16-
eliza = Person("Eliza", 34, "Arch Linux")
17+
eliza = Person("Eliza", 34, "Arch Linux", "456 Oak Ave")
1718
print(eliza.name)
18-
# print(eliza.address) # Error: address is not an attribute
19+
print(eliza.address)
1920

2021

21-
# This function will error at runtime if called
2222
def get_address(person: Person) -> str:
23-
return person.address # Error: Person has no attribute 'address'
23+
return person.address
2424

25-
# print(get_address(imran)) # Uncommenting this will cause an error
25+
print(get_address(imran))

0 commit comments

Comments
 (0)