From 15ce3169c032d3e29c200f2f1e50357e6ca5e6d4 Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Sat, 6 Jul 2019 11:34:47 +0800 Subject: [PATCH 1/9] 0191001 d1 work --- exercises/PanChuang2019/1001S02E01_helloworld.txt | 1 + exercises/PanChuang2019/README.md | 1 + 2 files changed, 2 insertions(+) create mode 100644 exercises/PanChuang2019/1001S02E01_helloworld.txt create mode 100644 exercises/PanChuang2019/README.md diff --git a/exercises/PanChuang2019/1001S02E01_helloworld.txt b/exercises/PanChuang2019/1001S02E01_helloworld.txt new file mode 100644 index 000000000..8f95ed72c --- /dev/null +++ b/exercises/PanChuang2019/1001S02E01_helloworld.txt @@ -0,0 +1 @@ +Human life is fleeting \ No newline at end of file diff --git a/exercises/PanChuang2019/README.md b/exercises/PanChuang2019/README.md new file mode 100644 index 000000000..93ec53aef --- /dev/null +++ b/exercises/PanChuang2019/README.md @@ -0,0 +1 @@ +# Human life is fleeting From f8d840146727588c1a903872b4effdad10de3f7e Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Fri, 12 Jul 2019 23:02:06 +0800 Subject: [PATCH 2/9] Create 1001S02E02_hello_python.py --- exercises/PanChuang2019/1001S02E02_hello_python.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 exercises/PanChuang2019/1001S02E02_hello_python.py diff --git a/exercises/PanChuang2019/1001S02E02_hello_python.py b/exercises/PanChuang2019/1001S02E02_hello_python.py new file mode 100644 index 000000000..7ddfc8f85 --- /dev/null +++ b/exercises/PanChuang2019/1001S02E02_hello_python.py @@ -0,0 +1 @@ +print('hello world!') \ No newline at end of file From 7661f285cd5ee8a43968ea0f85ffa175da6d7747 Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Sun, 20 Oct 2019 19:22:17 +0800 Subject: [PATCH 3/9] Create 1001S02E02_hello_world.py --- exercises/PanChuang2019/1001S02E02_hello_world.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 exercises/PanChuang2019/1001S02E02_hello_world.py diff --git a/exercises/PanChuang2019/1001S02E02_hello_world.py b/exercises/PanChuang2019/1001S02E02_hello_world.py new file mode 100644 index 000000000..010e86f20 --- /dev/null +++ b/exercises/PanChuang2019/1001S02E02_hello_world.py @@ -0,0 +1 @@ +print("Hello_Word") \ No newline at end of file From ae2a37f4cd2196e0dd208bbac8bcbee5f5acc74b Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Tue, 5 Nov 2019 23:31:08 +0800 Subject: [PATCH 4/9] Create 1001S02E03_calculator.py --- exercises/PanChuang2019/1001S02E03_calculator.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 exercises/PanChuang2019/1001S02E03_calculator.py diff --git a/exercises/PanChuang2019/1001S02E03_calculator.py b/exercises/PanChuang2019/1001S02E03_calculator.py new file mode 100644 index 000000000..2cb79ae5e --- /dev/null +++ b/exercises/PanChuang2019/1001S02E03_calculator.py @@ -0,0 +1,15 @@ +operator = input('请输入运算符(+、-、*、/):') +firstdata = input('请输入第一个数字:') +seconddata = input('请输入第二个数字:') +x = int(firstdata) +y = int(seconddata) +if operator=="+": + print(x,"+",y,"=",x+y) +elif operator=="-": + print(x,"-",y,"=",x-y) +elif operator=="*": + print(x,"*",y,"=",x*y) +elif operator=="/": + print(x,"/",y,"=",x/y) +else: + print("运算符输入错误") From 3bca359e1a7627f3f61f2ea2d686717b10a2812a Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Fri, 15 Nov 2019 07:40:29 +0800 Subject: [PATCH 5/9] Create 1001S02E04_control_flow.py --- exercises/PanChuang2019/1001S02E04_control_flow.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 exercises/PanChuang2019/1001S02E04_control_flow.py diff --git a/exercises/PanChuang2019/1001S02E04_control_flow.py b/exercises/PanChuang2019/1001S02E04_control_flow.py new file mode 100644 index 000000000..b70cb5df7 --- /dev/null +++ b/exercises/PanChuang2019/1001S02E04_control_flow.py @@ -0,0 +1,13 @@ +for i in range(1,10): + for j in range(1,i+1): + print('{}x{}={}'.format(i,j,i*j),end='\t') + print() + +for i in range(1,10): + while i%2==0: + break + else: + for j in range(1,i+1): + print(i,"*",j,"=",i*j,end="\t") + print() + continue \ No newline at end of file From 4fda942d66ca1a044c8076740d075377d360b333 Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Sun, 17 Nov 2019 19:31:06 +0800 Subject: [PATCH 6/9] Create 1001S02E05 work --- exercises/PanChuang2019/1001S02E05_array.py | 14 +++++++ .../PanChuang2019/1001S02E05_stats_text.py | 41 +++++++++++++++++++ exercises/PanChuang2019/1001S02E05_string.py | 35 ++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 exercises/PanChuang2019/1001S02E05_array.py create mode 100644 exercises/PanChuang2019/1001S02E05_stats_text.py create mode 100644 exercises/PanChuang2019/1001S02E05_string.py diff --git a/exercises/PanChuang2019/1001S02E05_array.py b/exercises/PanChuang2019/1001S02E05_array.py new file mode 100644 index 000000000..7bc69f8d8 --- /dev/null +++ b/exercises/PanChuang2019/1001S02E05_array.py @@ -0,0 +1,14 @@ +list=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +reversed_list=list[::-1] +print(reversed_list) +joined_str=''.join(str(i) for i in reversed_list) +print(joined_str) +sliced_str=joined_str[2:8] +print(sliced_str) +reversed_list=sliced_str[::-1] +print(reversed_list) +int_value=int(reversed_list) +print(int_value) +print(bin(int_value)) +print(oct(int_value)) +print(hex(int_value)) diff --git a/exercises/PanChuang2019/1001S02E05_stats_text.py b/exercises/PanChuang2019/1001S02E05_stats_text.py new file mode 100644 index 000000000..f6b051b62 --- /dev/null +++ b/exercises/PanChuang2019/1001S02E05_stats_text.py @@ -0,0 +1,41 @@ +text = ''' +The Zen of Python, by Tim Peters +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do +it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' +elements=text.split() +word_amount=[] +symbols="*.-,!" +for element in elements: + for symbol in symbols: + element=element.replace(symbol,'') + if len(element): + word_amount.append(element) +print(word_amount) + +counter={} +word_amount_set=set(word_amount) + +for word in word_amount_set: + counter[word]=word_amount.count(word) +print(counter) +print("这个是什么东东\n",counter.items()) +print("排序\n",sorted(counter.items(),key=lambda x:x[1],reverse=True)) diff --git a/exercises/PanChuang2019/1001S02E05_string.py b/exercises/PanChuang2019/1001S02E05_string.py new file mode 100644 index 000000000..c1e74a975 --- /dev/null +++ b/exercises/PanChuang2019/1001S02E05_string.py @@ -0,0 +1,35 @@ +text = ''' +The Zen of Python, by Tim Peters +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do +it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +text_New=text.replace("better","worse") +print('better变worse 的转换',text_New) +boom=text_New.split() +filter=[] +for word in boom: + if word.find('ea')==-1: + filter.append(word) +print(filter) +swapcased = [i.swapcase() for i in filter] +print(swapcased) +print(sorted(swapcased)) From ec63fac4f5a3d6e2ef7f460398bee47e22d80e8c Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Tue, 19 Nov 2019 00:42:48 +0800 Subject: [PATCH 7/9] Create 1001S02E06_stats_word.py --- .../PanChuang2019/1001S02E06_stats_word.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 exercises/PanChuang2019/1001S02E06_stats_word.py diff --git a/exercises/PanChuang2019/1001S02E06_stats_word.py b/exercises/PanChuang2019/1001S02E06_stats_word.py new file mode 100644 index 000000000..eef11bff1 --- /dev/null +++ b/exercises/PanChuang2019/1001S02E06_stats_word.py @@ -0,0 +1,69 @@ +def stats_text_en(text): + elements= text.split() + words=[] + symbols=',.*-!' + for element in elements: + for symbol in symbols: + element=element.replace(symbol,'') + if len(element): + words.append(element) + counter={} + word_set=set(words) + + for word in word_set: + counter[word]=words.count(word) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + +def stats_text_cn(text): + cn_characters=[] + for character in text: + if '\u4e00'<= character<='\u9fff': + cn_characters.append(character) + counter={} + cn_character_set=set(cn_characters) + for character in cn_character_set: + counter[character]=cn_characters.count(character) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + +en_text=''' +The Zen of Python, by Tim Peters +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do +it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +cn_text=''' +假如生活没有给你女朋友, +不要悲伤, +不要心急, +忧郁的日子需要的是镇静, +相信吧, +娶媳妇儿的日子将会到来 +... +一切都是肾虚, +一切都将过去, +而那春梦中的, +就将变成亲切的怀恋。 +''' +if __name__=='__main__': + en_turnout = stats_text_en(en_text) + cn_turnout = stats_text_cn(cn_text) + print('统计参数中每个英文出现的次数\n',en_turnout) + print('统计参数中每个汉字出现的次数\n',cn_turnout) \ No newline at end of file From 6b12a2b3c3269bc30df80106c95540ecf4ab9c17 Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Tue, 19 Nov 2019 23:01:39 +0800 Subject: [PATCH 8/9] Day 7 work (module) --- exercises/PanChuang2019/D07/main.py | 22 ++++++ .../PanChuang2019/D07/mymodule/stats_word.py | 75 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 exercises/PanChuang2019/D07/main.py create mode 100644 exercises/PanChuang2019/D07/mymodule/stats_word.py diff --git a/exercises/PanChuang2019/D07/main.py b/exercises/PanChuang2019/D07/main.py new file mode 100644 index 000000000..970ca5462 --- /dev/null +++ b/exercises/PanChuang2019/D07/main.py @@ -0,0 +1,22 @@ +from mymodule import stats_word + +sample_text=''' +了不起的盖茨比 + +我年纪还轻,阅历不深的时候,我父亲教导过我一句话, +我至今还念念不忘。 + +“每逢你想要批评任何人的时候,”他对我说, +“你就记住,这个世界上所有的人,并不是个个都有过你拥有的那些优越条件。” + +The Great Gatsby +In my younger and more vulnerable years my father gave me some advice +that I've been turning over in my mind ever since. +"Whenever you feel like criticising any one,"he told me, +"just remember that all the people in this world haven't had the advantages +that you've had." +''' + +result = stats_word.stats_text(sample_text) +print('统计结果\n',result) + \ No newline at end of file diff --git a/exercises/PanChuang2019/D07/mymodule/stats_word.py b/exercises/PanChuang2019/D07/mymodule/stats_word.py new file mode 100644 index 000000000..1b0568f5a --- /dev/null +++ b/exercises/PanChuang2019/D07/mymodule/stats_word.py @@ -0,0 +1,75 @@ +def stats_text_en(text): + elements= text.split() + words=[] + symbols=',.*-!' + for element in elements: + for symbol in symbols: + element=element.replace(symbol,'') + if len(element) and element.isascii(): + words.append(element) + counter={} + word_set=set(words) + + for word in word_set: + counter[word]=words.count(word) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + +def stats_text_cn(text): + cn_characters=[] + for character in text: + if '\u4e00'<= character<='\u9fff': + cn_characters.append(character) + counter={} + cn_character_set=set(cn_characters) + for character in cn_character_set: + counter[character]=cn_characters.count(character) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + +#合并中文词频和英文词频的结果 +def stats_text(text): + return stats_text_cn(text) + stats_text_en(text) + + +en_text=''' +The Zen of Python, by Tim Peters +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do +it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +cn_text=''' +假如生活没有给你女朋友, +不要悲伤, +不要心急, +忧郁的日子需要的是镇静, +相信吧, +娶媳妇儿的日子将会到来 +... +一切都是肾虚, +一切都将过去, +而那春梦中的, +就将变成亲切的怀恋。 +''' +if __name__=='__main__': + en_turnout = stats_text_en(en_text) + cn_turnout = stats_text_cn(cn_text) + print('统计参数中每个英文出现的次数\n',en_turnout) + print('统计参数中每个汉字出现的次数\n',cn_turnout) + print(stats_text) \ No newline at end of file From 1a9bf505e449d6e1d0665d9c01f1ae566bd13488 Mon Sep 17 00:00:00 2001 From: PanChuang2019 Date: Thu, 21 Nov 2019 23:04:00 +0800 Subject: [PATCH 9/9] Traceback and Logging --- exercises/PanChuang2019/D08/main.py | 30 +++++++ .../PanChuang2019/D08/mymodule/stats_word.py | 81 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 exercises/PanChuang2019/D08/main.py create mode 100644 exercises/PanChuang2019/D08/mymodule/stats_word.py diff --git a/exercises/PanChuang2019/D08/main.py b/exercises/PanChuang2019/D08/main.py new file mode 100644 index 000000000..4ea91f43c --- /dev/null +++ b/exercises/PanChuang2019/D08/main.py @@ -0,0 +1,30 @@ +from mymodule import stats_word +import traceback +import logging + +logger = logging.getLogger(__name__) + + +def test_traceback(): + try: + stats_word.stats_text(1) + except Exception as e: + print('test_traceback =>', e) + print(traceback.format_exc()) + + +def test_logger(): + try: + stats_word.stats_text(1) + except Exception as e: + print('test_logger =>', e) + logger.exception(e) + + +if __name__=="__main__": + # stats_word.stats.text(1) + test_traceback() + test_logger() + + + \ No newline at end of file diff --git a/exercises/PanChuang2019/D08/mymodule/stats_word.py b/exercises/PanChuang2019/D08/mymodule/stats_word.py new file mode 100644 index 000000000..1f8b89252 --- /dev/null +++ b/exercises/PanChuang2019/D08/mymodule/stats_word.py @@ -0,0 +1,81 @@ +def stats_text_en(text): + if not isinstance(text,str): + raise ValueError('参数必须是str类型,输入类型%s' % type(text)) + elements= text.split() + words=[] + symbols=',.*-!' + for element in elements: + for symbol in symbols: + element=element.replace(symbol,'') + if len(element) and element.isascii(): + words.append(element) + counter={} + word_set=set(words) + + for word in word_set: + counter[word]=words.count(word) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + +def stats_text_cn(text): + if not isinstance(text,str): + raise ValueError('参数必须是str类型,输入类型%s' % type(text)) + cn_characters=[] + for character in text: + if '\u4e00'<= character<='\u9fff': + cn_characters.append(character) + counter={} + cn_character_set=set(cn_characters) + for character in cn_character_set: + counter[character]=cn_characters.count(character) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + +#合并中文词频和英文词频的结果 +def stats_text(text): + if not isinstance(text,str): + raise ValueError('参数必须是str类型,输入类型%s' % type(text)) + return stats_text_cn(text) + stats_text_en(text) + + +en_text=''' +The Zen of Python, by Tim Peters +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do +it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +cn_text=''' +假如生活没有给你女朋友, +不要悲伤, +不要心急, +忧郁的日子需要的是镇静, +相信吧, +娶媳妇儿的日子将会到来 +... +一切都是肾虚, +一切都将过去, +而那春梦中的, +就将变成亲切的怀恋。 +''' +if __name__=='__main__': + en_turnout = stats_text_en(en_text) + cn_turnout = stats_text_cn(cn_text) + print('统计参数中每个英文出现的次数\n',en_turnout) + print('统计参数中每个汉字出现的次数\n',cn_turnout) + print(stats_text) \ No newline at end of file