Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db43898

Browse files
committed
adicionando novo exemplo
1 parent bd8e15e commit db43898

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed
791 Bytes
Binary file not shown.
1.18 KB
Binary file not shown.
16 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import shelve
2+
3+
4+
5+
db = shelve.open('class-shelve')
6+
7+
for key in db:
8+
print(key, '->\n ', db[key].name, db[key].pay)
9+
10+
bob = db['bob']
11+
sue = db['sue']
12+
tom = db['tom']
13+
14+
print(bob.last_name())
15+
print(sue.last_name())
16+
print(tom.last_name())
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import shelve
2+
from person import Person
3+
from manager import Manager
4+
5+
6+
p1 = Person('bob smith', 42, 30000, 'software')
7+
p2 = Person('sue jones', 25, 40000, 'hardware')
8+
p3 = Person('tom tolis', 50, 50000)
9+
10+
db = shelve.open('class-shelve')
11+
db['bob'] = p1
12+
db['sue'] = p2
13+
db['tom'] = p3
14+
db.close()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from person import Person
2+
3+
4+
5+
class Manager(Person):
6+
def giveRaise(self, percent, bonus=0.1):
7+
self.pay *= (float('1.' + str(percent)) + bonus)
8+
9+
10+
if __name__ == '__main__':
11+
tom = Manager(name='tom tolis', age=50, pay=5000)
12+
13+
print(tom.last_name())
14+
print(tom.pay)
15+
16+
tom.giveRaise(20)
17+
print(tom.pay)
18+
19+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Person:
2+
def __init__(self, name, age, pay=0, job=None):
3+
self.name = name.title()
4+
self.age = age
5+
self.pay = pay
6+
self.job = job
7+
8+
# return ultimo nome
9+
def last_name(self):
10+
return self.name.split()[-1]
11+
12+
# dar aumento salarial
13+
def giveRaise(self, percent):
14+
self.pay *= float('1.' + str(percent))
15+
16+
if __name__ == '__main__':
17+
bob = Person('bob smith', 42, 3000, 'software')
18+
sue = Person('sue jones', 45, 4000, 'hardware')
19+
jonas = Person('jonas tes', 27, 1000, 'software')
20+
21+
print(sue.name)
22+
print(sue.pay)
23+
24+
sue.giveRaise(10)
25+
print(sue.pay)
26+
27+
print(bob.name)
28+
print(bob.job)
29+
30+
print(jonas.last_name())
31+
print(jonas.job)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import shelve
2+
3+
4+
5+
db = shelve.open('class-shelve')
6+
7+
sue = db['sue'] # puxando
8+
sue.giveRaise(25) # dando aumento
9+
db['sue'] = sue # mandando de volta
10+
11+
tom = db['tom']
12+
tom.giveRaise(20)
13+
db['tom'] = tom
14+
15+
db.close()
16+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /