forked from guoylyy/uband-python-s1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10-homework-02.py
39 lines (31 loc) · 1.08 KB
/
day10-homework-02.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: xxx
# 实现了和 homework01 一样的功能
# 供你分析和对比
def homework2():
book = {
"abandon": 'to give up to the control or influence of another person or agent',
"abase": "to lower in rank, office, prestige, or esteem",
"abash" : "to destroy the self-possession or self-confidence of"
}
who = '老爸'
tear_word = 'abandon' #可能会被撕毁的页的key
print '%s在看一本英文书' % (who)
if not search('etiquette', book, who):
tear_mean = book[tear_word]
del book[tear_word]
print '%s撕毁了 %s 的页面' % (who, tear_word)
if search('abase', book, who):
#老爸黏贴了代码
book[tear_word] = tear_mean
print '%s把 %s 的字典页又贴上了' % (who, tear_word)
def search(key, dictionary, who):
if dictionary.has_key(key):
print '%s 查询到了 %s:%s' % (who, key, dictionary[key])
return True
else:
print '%s 没有查询到 %s 的意思' %(who, key)
return False
if __name__ == '__main__':
homework2()