-
Notifications
You must be signed in to change notification settings - Fork 0
/
bite167.py
52 lines (42 loc) · 1.47 KB
/
bite167.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
class User:
"""A User class
(Django's User model inspired us)
"""
def __init__(self, first_name, last_name):
"""Constructor, base values"""
self.first_name = first_name
self.last_name = last_name
@property
def get_full_name(self):
"""Return first separated by a whitespace
and using title case for both.
"""
return self.first_name.capitalize() + ' ' + self.last_name.capitalize()
@property
def username(self):
"""A username consists of the first char of
the user's first_name and the first 7 chars
of the user's lowercased last_name.
If this is your first property, check out:
https://pybit.es/property-decorator.html
"""
return self.first_name[0].lower() + self.last_name[:7].lower()
# TODO 3: you code
#
# add a __str__ and a __repr__
# see: https://stackoverflow.com/a/1438297
# "__repr__ is for devs, __str__ is for customers"
#
# see also TESTS for required output
def __str__(self):
return '{} ({})'.format(self.get_full_name, self.username)
def __repr__(self):
"""Don't hardcode the class name, hint: use a
special attribute of self.__class__ ...
"""
return '{}("{}", "{}")'.format(self.__class__.__name__, self.first_name, self.last_name)
bob = User('bob', 'belderbos')
print(bob.get_full_name)
print(bob.username)
print(str(bob))
print(repr(bob))