Skip to content

Commit fd9ab6f

Browse files
committed
preview
1 parent 8d011db commit fd9ab6f

4 files changed

Lines changed: 169 additions & 0 deletions

File tree

Preview/Preview.ipynb

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## p28"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"from person_start import Person\n",
17+
"bob = Person('Bob Smith', 42)\n",
18+
"sue = Person('Sue Jones', 45, 40000)"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 2,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"name": "stdout",
28+
"output_type": "stream",
29+
"text": [
30+
"Bob Smith 0\n",
31+
"Sue Jones 40000\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"people = [bob, sue]\n",
37+
"for person in people:\n",
38+
" print(person.name, person.pay)"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 3,
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"data": {
48+
"text/plain": [
49+
"[('Bob Smith', 0), ('Sue Jones', 40000)]"
50+
]
51+
},
52+
"execution_count": 3,
53+
"metadata": {},
54+
"output_type": "execute_result"
55+
}
56+
],
57+
"source": [
58+
"x = [(person.name, person.pay) for person in people]\n",
59+
"x"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 4,
65+
"metadata": {},
66+
"outputs": [
67+
{
68+
"data": {
69+
"text/plain": [
70+
"['Sue Jones']"
71+
]
72+
},
73+
"execution_count": 4,
74+
"metadata": {},
75+
"output_type": "execute_result"
76+
}
77+
],
78+
"source": [
79+
"[rec.name for rec in people if rec.age >= 45]"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 5,
85+
"metadata": {},
86+
"outputs": [
87+
{
88+
"data": {
89+
"text/plain": [
90+
"[42, 2025]"
91+
]
92+
},
93+
"execution_count": 5,
94+
"metadata": {},
95+
"output_type": "execute_result"
96+
}
97+
],
98+
"source": [
99+
"[(rec.age ** 2 if rec.age >= 45 else rec.age) for rec in people]"
100+
]
101+
}
102+
],
103+
"metadata": {
104+
"kernelspec": {
105+
"display_name": "Python 3",
106+
"language": "python",
107+
"name": "python3"
108+
},
109+
"language_info": {
110+
"codemirror_mode": {
111+
"name": "ipython",
112+
"version": 3
113+
},
114+
"file_extension": ".py",
115+
"mimetype": "text/x-python",
116+
"name": "python",
117+
"nbconvert_exporter": "python",
118+
"pygments_lexer": "ipython3",
119+
"version": "3.6.4"
120+
}
121+
},
122+
"nbformat": 4,
123+
"nbformat_minor": 2
124+
}

Preview/manager.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from person import Person
2+
3+
class Manager(Person):
4+
def giveRaise(self, percent, bonus=0.1):
5+
self.pay *= (1.0 + percent + bonus)
6+
7+
if __name__ == '__main__':
8+
tom = Manager(name='Tom Doe', age=50, pay=50000)
9+
print(tom.lastName())
10+
tom.giveRaise(.20)
11+
print(tom.pay)

Preview/person.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Person:
2+
def __init__(self, name, age, pay=0, job=None):
3+
self.name = name
4+
self.age = age
5+
self.pay = pay
6+
self.job = job
7+
def lastName(self):
8+
return self.name.split()[-1]
9+
def giveRaise(self, percent):
10+
self.pay *= (1.0 + percent)
11+
12+
if __name__ == '__main__':
13+
bob = Person('Bob Smith', 42, 30000, 'software')
14+
sue = Person('Sue Jones', 45, 40000, 'hardware')
15+
print(bob.name, sue.pay)
16+
17+
print(bob.lastName())
18+
sue.giveRaise(.10)
19+
print(sue.pay)

Preview/person_start.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Person:
2+
def __init__(self, name, age, pay=0, job=None):
3+
self.name = name
4+
self.age = age
5+
self.pay = pay
6+
self.job = job
7+
8+
if __name__ == '__main__':
9+
bob = Person('Bob Smith', 42, 30000, 'software')
10+
sue = Person('Sue Jones', 45, 40000, 'hardware')
11+
print(bob.name, sue.pay)
12+
13+
print(bob.name.split()[-1])
14+
sue.pay *= 1.10
15+
print(sue.pay)

0 commit comments

Comments
 (0)