Skip to content

Commit fd78436

Browse files
committed
exercise 5 completed
1 parent 232223e commit fd78436

2 files changed

Lines changed: 35 additions & 19 deletions

File tree

‎Sprint 5 Prep Exercises/exercise_4.py‎

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Person:
2+
def __init__(self, name: str, age: int, preferred_operating_system: str):
3+
self.name = name
4+
self.age = age
5+
self.preferred_operating_system = preferred_operating_system
6+
7+
imran = Person("Imran", 22, "Ubuntu")
8+
print(imran.name)
9+
print(imran.address)
10+
11+
eliza = Person("Eliza", 34, "Arch Linux")
12+
print(eliza.name)
13+
print(eliza.address)
14+
15+
# exercise_4_and_5.py:9: error: "Person" has no attribute "address" [attr-defined]
16+
# exercise_4_and_5.py:13: error: "Person" has no attribute "address" [attr-defined]
17+
# Found 2 errors in 1 file (checked 1 source file)
18+
19+
# There is no address attribute for a Person, only name, age and preferred operating system.
20+
21+
# Add the is_adult code to the file you saved earlier.
22+
def is_adult(person: Person) -> bool:
23+
return person.age >= 18
24+
25+
print(is_adult(imran))
26+
27+
# Run it through mypy - notice that no errors are reported -
28+
# mypy understands that Person has a property named age so is happy with the function.
29+
30+
def is_banana(person: Person) -> bool:
31+
return person.banana
32+
33+
print(is_banana(imran))
34+
35+
# exercise_4_and_5.py:31: error: "Person" has no attribute "banana" [attr-defined]

0 commit comments

Comments
 (0)