This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
forked from slgraff/edx-mitx-6.00.1x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
final-prob6.py
83 lines (72 loc) · 2.43 KB
/
final-prob6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# final-prob6.py
#
# Final Exam, Problem 6
#
# edX MITx 6.00.1x
# Introduction to Computer Science and Programming Using Python
"""
In this problem, you will implement a class according to the specifications
in the template file usresident.py. The file contains a Person class similar
to what you have seen in lecture and a USResident class (a subclass of Person).
Person is already implemented for you and you will have to implement two
methods of USResident.
For example, the following code:
a = USResident('Tim Beaver', 'citizen')
print a.getStatus()
b = USResident('Tim Horton', 'non-resident')
will print out:
citizen
## will show that a ValueError was raised at a particular line
Paste only your implementation of the USResident class in the box.
Do not leave any debugging print statements.
"""
## DO NOT MODIFY THE IMPLEMENTATION OF THE Person CLASS ##
class Person(object):
def __init__(self, name):
#create a person with name name
self.name = name
try:
firstBlank = name.rindex(' ')
self.lastName = name[firstBlank+1:]
except:
self.lastName = name
self.age = None
def getLastName(self):
#return self's last name
return self.lastName
def setAge(self, age):
#assumes age is an int greater than 0
#sets self's age to age (in years)
self.age = age
def getAge(self):
#assumes that self's age has been set
#returns self's current age in years
if self.age == None:
raise ValueError
return self.age
def __lt__(self, other):
#return True if self's name is lexicographically less
#than other's name, and False otherwise
if self.lastName == other.lastName:
return self.name < other.name
return self.lastName < other.lastName
def __str__(self):
#return self's name
return self.name
class USResident(Person):
"""
A Person who resides in the US.
"""
def __init__(self, name, status):
"""
Initializes a Person object. A USResident object inherits
from Person and has one additional attribute:
status: a string, one of "citizen", "legal_resident", "illegal_resident"
Raises a ValueError if status is not one of those 3 strings
"""
# Write your code here
def getStatus(self):
"""
Returns the status
"""
# Write your code here