From 4fea5e516189e75e392d9c369e2e738dee795be2 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Sat, 10 Aug 2019 10:09:56 +0800 Subject: [PATCH 01/15] Day1 Homework Create two txt files. --- exercises/PerryZ10/1001S02E01_helloworld.txt.txt | 1 + exercises/PerryZ10/README.md.txt | 0 2 files changed, 1 insertion(+) create mode 100644 exercises/PerryZ10/1001S02E01_helloworld.txt.txt create mode 100644 exercises/PerryZ10/README.md.txt diff --git a/exercises/PerryZ10/1001S02E01_helloworld.txt.txt b/exercises/PerryZ10/1001S02E01_helloworld.txt.txt new file mode 100644 index 000000000..394a64ef9 --- /dev/null +++ b/exercises/PerryZ10/1001S02E01_helloworld.txt.txt @@ -0,0 +1 @@ +Hello! I'm new here. \ No newline at end of file diff --git a/exercises/PerryZ10/README.md.txt b/exercises/PerryZ10/README.md.txt new file mode 100644 index 000000000..e69de29bb From 36a8e8fb19785fd981a3ebbf867220eb217ccb84 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Sat, 10 Aug 2019 10:40:46 +0800 Subject: [PATCH 02/15] Change Readme txt file to md file Change Readme txt file to md file --- exercises/PerryZ10/{README.md.txt => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/PerryZ10/{README.md.txt => README.md} (100%) diff --git a/exercises/PerryZ10/README.md.txt b/exercises/PerryZ10/README.md similarity index 100% rename from exercises/PerryZ10/README.md.txt rename to exercises/PerryZ10/README.md From f6ccc9c397eaf6d1dbc473f8246dcaddd3940ad6 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Mon, 12 Aug 2019 22:32:25 +0800 Subject: [PATCH 03/15] ID Change, Txt File, Hello Python Change of Day1: ID and correct helloworld.txt file Day 2 homework --- .../1001S02E01_helloworld.txt} | 0 exercises/1901100283/1001S02E02_hello_python.py | 2 ++ exercises/{PerryZ10 => 1901100283}/README.md | 0 3 files changed, 2 insertions(+) rename exercises/{PerryZ10/1001S02E01_helloworld.txt.txt => 1901100283/1001S02E01_helloworld.txt} (100%) create mode 100644 exercises/1901100283/1001S02E02_hello_python.py rename exercises/{PerryZ10 => 1901100283}/README.md (100%) diff --git a/exercises/PerryZ10/1001S02E01_helloworld.txt.txt b/exercises/1901100283/1001S02E01_helloworld.txt similarity index 100% rename from exercises/PerryZ10/1001S02E01_helloworld.txt.txt rename to exercises/1901100283/1001S02E01_helloworld.txt diff --git a/exercises/1901100283/1001S02E02_hello_python.py b/exercises/1901100283/1001S02E02_hello_python.py new file mode 100644 index 000000000..5b594299d --- /dev/null +++ b/exercises/1901100283/1001S02E02_hello_python.py @@ -0,0 +1,2 @@ +msg = "hello world" +print(msg) \ No newline at end of file diff --git a/exercises/PerryZ10/README.md b/exercises/1901100283/README.md similarity index 100% rename from exercises/PerryZ10/README.md rename to exercises/1901100283/README.md From 20b6a2791abf34aa7a4c620cf210d0029c609ba3 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Wed, 14 Aug 2019 22:51:34 +0800 Subject: [PATCH 04/15] Create 1001S02E03_calculator.py Caculator --- exercises/1901100283/1001S02E03_calculator.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 exercises/1901100283/1001S02E03_calculator.py diff --git a/exercises/1901100283/1001S02E03_calculator.py b/exercises/1901100283/1001S02E03_calculator.py new file mode 100644 index 000000000..9c806124a --- /dev/null +++ b/exercises/1901100283/1001S02E03_calculator.py @@ -0,0 +1,29 @@ +def add(x, y): + return x + y +def subtract(x, y): + return x - y +def multiply(x, y): + return x * y +def divide(x, y): + return x / y + +print("请选择运算:") +print("1、相加") +print("2、相减") +print("3、相乘") +print("4、相除") + +choice = input("请输入您的选择(1/2/3/4):") +num1 = int(input("请输入第一个数字:")) +num2 = int(input("请输入第二个数字:")) + +if choice == '1': + print(num1,"+",num2,"=",add(num1,num2)) +elif choice == '2': + print(num1,"-",num2,"=",subtract(num1,num2)) +elif choice == '3': + print(num1,"*",num2,"=",multiply(num1,num2)) +elif choice == '4': + print(num1,"/",num2,"=",divide(num1,num2)) +else: + print("非法输入!") \ No newline at end of file From 9a635b1a146fea34ef2c6b5f5afc295561d5b2c7 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Sat, 17 Aug 2019 06:07:25 +0800 Subject: [PATCH 05/15] Create 1001S02E04_control_flow.py Task 1 and Task 2 (2 solutions) --- .../1901100283/1001S02E04_control_flow.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 exercises/1901100283/1001S02E04_control_flow.py diff --git a/exercises/1901100283/1001S02E04_control_flow.py b/exercises/1901100283/1001S02E04_control_flow.py new file mode 100644 index 000000000..4192c6da4 --- /dev/null +++ b/exercises/1901100283/1001S02E04_control_flow.py @@ -0,0 +1,29 @@ +#Task1: for...in方法 +for a in range(1,10): + for b in range(1, a + 1): + print("{}*{}={}".format(a, b ,a * b), end="\t") + print() + +#Task 2: while方法+条件判断 +a = 1 +while a <= 9: + if a % 2 == 1: + b = 1 + while b <= a: + print("{}*{}={}".format(a, b ,a * b), end="\t") + b = b + 1 + print() + a= a + 1 + + +#Task 2: while方法+另一解决方案 +a = 1 +while a <= 9: + b = 1 + while b <= a: + print("{}*{}={}".format(a, b ,a * b), end="\t") + b = b + 1 + print() + a= a + 2 + + From b1d224ad0a8677bafb5d5b28e2e5b11451d98562 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Thu, 22 Aug 2019 06:29:16 +0800 Subject: [PATCH 06/15] Day 5 Homework --- exercises/1901100283/1001S02E05_array.py | 11 ++++ exercises/1901100283/1001S02E05_stats_text.py | 51 +++++++++++++++++++ exercises/1901100283/1001S02E05_string.py | 40 +++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 exercises/1901100283/1001S02E05_array.py create mode 100644 exercises/1901100283/1001S02E05_stats_text.py create mode 100644 exercises/1901100283/1001S02E05_string.py diff --git a/exercises/1901100283/1001S02E05_array.py b/exercises/1901100283/1001S02E05_array.py new file mode 100644 index 000000000..735a3653d --- /dev/null +++ b/exercises/1901100283/1001S02E05_array.py @@ -0,0 +1,11 @@ +num_list=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +num_list.reverse() +num_str=[str(i) for i in num_list] +x="".join(num_str) +n=list(x[2:8]) +n.reverse() +str1="".join(n) +num1=int(str1) +print(bin(num1)) +print(oct(num1)) +print(hex(num1)) \ No newline at end of file diff --git a/exercises/1901100283/1001S02E05_stats_text.py b/exercises/1901100283/1001S02E05_stats_text.py new file mode 100644 index 000000000..3d3627f4e --- /dev/null +++ b/exercises/1901100283/1001S02E05_stats_text.py @@ -0,0 +1,51 @@ +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! +''' +print("Solution 1: zip方法") +a=text.split() +x=[] +for i in a: + if i.isalpha() is True: + x.append(i) +c=[] +for i in x: + b=x.count(i) + c.append(b) +n_dic=dict(zip(x,c)) +sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) +print(dict(sorted_dic)) + +print("Solution 2: dict方法") +a=text.split() +x=[] +for i in a: + if i.isalpha() is True: + x.append(i) +n_dic={} +for word in x: + if word not in n_dic: + n_dic[word]=1 + else: + n_dic[word]=n_dic[word]+1 +sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) +print(dict(sorted_dic)) diff --git a/exercises/1901100283/1001S02E05_string.py b/exercises/1901100283/1001S02E05_string.py new file mode 100644 index 000000000..a3fe9e286 --- /dev/null +++ b/exercises/1901100283/1001S02E05_string.py @@ -0,0 +1,40 @@ +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! +''' + +a = text.replace('better', 'worse') +b=a.split() +x=[] +for i in b: + if 'ea' not in i: + x.append(i) + else: + continue +n=[] +for i in x: + c=i.swapcase() + n.append(c) +n.sort() +print(n) \ No newline at end of file From 1e0b9de6af312812c8ef3a77b38c1c7efc1bedb4 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Sat, 24 Aug 2019 05:49:56 +0800 Subject: [PATCH 07/15] Create 1001S02E06_stats_word.py --- exercises/1901100283/1001S02E06_stats_word.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 exercises/1901100283/1001S02E06_stats_word.py diff --git a/exercises/1901100283/1001S02E06_stats_word.py b/exercises/1901100283/1001S02E06_stats_word.py new file mode 100644 index 000000000..f3cd7fc25 --- /dev/null +++ b/exercises/1901100283/1001S02E06_stats_word.py @@ -0,0 +1,34 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + n_dic={} + for word in x: + if word not in n_dic: + n_dic[word]=1 + else: + n_dic[word]=n_dic[word]+1 + sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) + print(dict(sorted_dic)) + + +#stats_text_cn 封装统计中文汉字字频的函数 +def stats_text_cn(text): + a=list(text) + x=[] + for i in a: + if '\u4e00'<=i<='\u9fa5': + x.append(i) + n_dic={} + for word in x: + if word not in n_dic: + n_dic[word]=1 + else: + n_dic[word]=n_dic[word]+1 + sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) + print(dict(sorted_dic)) + + From 177de1bab373a1304e66a2ead637130024113271 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Tue, 27 Aug 2019 05:28:34 +0800 Subject: [PATCH 08/15] Day 7 Homework Update on Day 6 and Day 7 homework. --- exercises/1901100283/1001S02E06_stats_word.py | 4 +- exercises/1901100283/d07/mymodule/main.py | 63 +++++++++++++++++++ .../1901100283/d07/mymodule/stats_word.py | 39 ++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 exercises/1901100283/d07/mymodule/main.py create mode 100644 exercises/1901100283/d07/mymodule/stats_word.py diff --git a/exercises/1901100283/1001S02E06_stats_word.py b/exercises/1901100283/1001S02E06_stats_word.py index f3cd7fc25..242bc8695 100644 --- a/exercises/1901100283/1001S02E06_stats_word.py +++ b/exercises/1901100283/1001S02E06_stats_word.py @@ -12,7 +12,7 @@ def stats_text_en(text): else: n_dic[word]=n_dic[word]+1 sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) - print(dict(sorted_dic)) + return dict(sorted_dic) #stats_text_cn 封装统计中文汉字字频的函数 @@ -29,6 +29,6 @@ def stats_text_cn(text): else: n_dic[word]=n_dic[word]+1 sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) - print(dict(sorted_dic)) + return dict(sorted_dic) diff --git a/exercises/1901100283/d07/mymodule/main.py b/exercises/1901100283/d07/mymodule/main.py new file mode 100644 index 000000000..73e0a34b8 --- /dev/null +++ b/exercises/1901100283/d07/mymodule/main.py @@ -0,0 +1,63 @@ +from stats_word import stats_text + +text = ''' +愚公移⼭山 +太⾏行行,王屋⼆二⼭山的北北⾯面,住了了⼀一個九⼗十歲的⽼老老翁,名叫愚公。⼆二⼭山佔地廣闊,擋住去路路,使他 +和家⼈人往來來極為不不便便。 +⼀一天,愚公召集家⼈人說:「讓我們各盡其⼒力力,剷平⼆二⼭山,開條道路路,直通豫州,你們認為怎 +樣?」 +⼤大家都異異⼝口同聲贊成,只有他的妻⼦子表示懷疑,並說:「你連開鑿⼀一個⼩小丘的⼒力力量量都沒有,怎 +可能剷平太⾏行行、王屋⼆二⼭山呢?況且,鑿出的⼟土⽯石⼜又丟到哪裏去呢?」 +⼤大家都熱烈烈地說:「把⼟土⽯石丟進渤海海裏。」 +於是愚公就和兒孫,⼀一起開挖⼟土,把⼟土⽯石搬運到渤海海去。 +愚公的鄰居是個寡婦,有個兒⼦子⼋八歲也興致勃勃地⾛走來來幫忙。 +寒來來暑往,他們要⼀一年年才能往返渤海海⼀一次。 +住在⿈黃河河畔的智叟,看⾒見見他們這樣⾟辛苦,取笑愚公說:「你不不是很愚蠢嗎?你已⼀一把年年紀 +了了,就是⽤用盡你的氣⼒力力,也不不能挖去⼭山的⼀一⻆角呢?」 +愚公歎息道:「你有這樣的成⾒見見,是不不會明⽩白的。你⽐比那寡婦的⼩小兒⼦子還不不如呢!就算我死 +了了,還有我的兒⼦子,我的孫⼦子,我的曾孫⼦子,他們⼀一直傳下去。⽽而這⼆二⼭山是不不會加⼤大的,總有 +⼀一天,我們會把它們剷平。」 +智叟聽了了,無話可說: +⼆二⼭山的守護神被愚公的堅毅精神嚇倒,便便把此事奏知天帝。天帝佩服愚公的精神,就命兩位⼤大 +⼒力力神揹⾛走⼆二⼭山。 +How The Foolish Old Man Moved Mountains +Yugong was a ninety-year-old man who lived at the north of two high +mountains, Mount Taixing and Mount Wangwu. +Stretching over a wide expanse of land, the mountains blocked +yugong’s way making it inconvenient for him and his family to get +around. +One day yugong gathered his family together and said,”Let’s do our +best to level these two mountains. We shall open a road that leads +to Yuzhou. What do you think?” +All but his wife agreed with him. +“You don’t have the strength to cut even a small mound,” muttered +his wife. “How on earth do you suppose you can level Mount Taixin +and Mount Wanwu? Moreover, where will all the earth and rubble go?” +“Dump them into the Sea of Bohai!” said everyone. +So Yugong, his sons, and his grandsons started to break up rocks and +remove the earth. They transported the earth and rubble to the Sea +of Bohai. +Now Yugong’s neighbour was a widow who had an only child eight years +old. Evening the young boy offered his help eagerly. +Summer went by and winter came. It took Yugong and his crew a full +year to travel back and forth once. +On the bank of the Yellow River dwelled an old man much respected +for his wisdom. When he saw their back-breaking labour, he ridiculed +Yugong saying,”Aren’t you foolish, my friend? You are very old now, +and with whatever remains of your waning strength, you won’t be able +to remove even a corner of the mountain.” +Yugong uttered a sigh and said,”A biased person like you will never +understand. You can’t even compare with the widow’s little boy!” +“Even if I were dead, there will still be my children, my +grandchildren, my great grandchildren, my great great grandchildren. +They descendants will go on forever. But these mountains will not +grow any taler. We shall level them one day!” he declared with +confidence. +The wise old man was totally silenced. +When the guardian gods of the mountains saw how determined Yugong +and his crew were, they were struck with fear and reported the +incident to the Emperor of Heavens. +Filled with admiration for Yugong, the Emperor of Heavens ordered +two mighty gods to carry the mountains away. +''' +print(stats_text(text)) \ No newline at end of file diff --git a/exercises/1901100283/d07/mymodule/stats_word.py b/exercises/1901100283/d07/mymodule/stats_word.py new file mode 100644 index 000000000..2da39be6c --- /dev/null +++ b/exercises/1901100283/d07/mymodule/stats_word.py @@ -0,0 +1,39 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + n_dic={} + for word in x: + if word not in n_dic: + n_dic[word]=1 + else: + n_dic[word]=n_dic[word]+1 + sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) + return dict(sorted_dic) + + +#stats_text_cn 封装统计中文汉字字频的函数 +def stats_text_cn(text): + a=list(text) + x=[] + for i in a: + if '\u4e00'<=i<='\u9fa5': + x.append(i) + n_dic={} + for word in x: + if word not in n_dic: + n_dic[word]=1 + else: + n_dic[word]=n_dic[word]+1 + sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) + return dict(sorted_dic) + +#stats_text 分别调用stats_text_en , stats_text_cn ,输出合并词频统计结果 +def stats_text(text): + new_dic=dict(stats_text_en(text),**stats_text_cn(text)) + return new_dic + + From 4d16bfac09b42762e38172311371f27ac8cefeed Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Wed, 28 Aug 2019 06:35:34 +0800 Subject: [PATCH 09/15] Day 8 Homework --- exercises/1901100283/d08/mymodule/main.py | 6 +++ .../1901100283/d08/mymodule/stats_word.py | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 exercises/1901100283/d08/mymodule/main.py create mode 100644 exercises/1901100283/d08/mymodule/stats_word.py diff --git a/exercises/1901100283/d08/mymodule/main.py b/exercises/1901100283/d08/mymodule/main.py new file mode 100644 index 000000000..2d2afc5e4 --- /dev/null +++ b/exercises/1901100283/d08/mymodule/main.py @@ -0,0 +1,6 @@ +from stats_word import stats_text +text=123 +try: + print(stats_text(text)) +except ValueError: + print('请重新输入字符串内容!') diff --git a/exercises/1901100283/d08/mymodule/stats_word.py b/exercises/1901100283/d08/mymodule/stats_word.py new file mode 100644 index 000000000..0099b853b --- /dev/null +++ b/exercises/1901100283/d08/mymodule/stats_word.py @@ -0,0 +1,49 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + else: + pass + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + n_dic={} + for word in x: + if word not in n_dic: + n_dic[word]=1 + else: + n_dic[word]=n_dic[word]+1 + sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) + return dict(sorted_dic) + + +#stats_text_cn 封装统计中文汉字字频的函数 +def stats_text_cn(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + a=list(text) + x=[] + for i in a: + if '\u4e00'<=i<='\u9fa5': + x.append(i) + n_dic={} + for word in x: + if word not in n_dic: + n_dic[word]=1 + else: + n_dic[word]=n_dic[word]+1 + sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) + return dict(sorted_dic) + +#stats_text 分别调用stats_text_en , stats_text_cn ,输出合并词频统计结果 +def stats_text(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + new_dic=dict(stats_text_en(text),**stats_text_cn(text)) + return new_dic + From 334cd5462ab27667efdd4a87b659c457cf9e537a Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Mon, 2 Sep 2019 06:12:55 +0800 Subject: [PATCH 10/15] Day 9 Homework --- exercises/1901100283/1001S02E06_stats_word.py | 6 --- exercises/1901100283/d09/mymodule/main.py | 6 +++ .../1901100283/d09/mymodule/stats_word.py | 45 +++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 exercises/1901100283/d09/mymodule/main.py create mode 100644 exercises/1901100283/d09/mymodule/stats_word.py diff --git a/exercises/1901100283/1001S02E06_stats_word.py b/exercises/1901100283/1001S02E06_stats_word.py index 97de3b0eb..48cf69452 100644 --- a/exercises/1901100283/1001S02E06_stats_word.py +++ b/exercises/1901100283/1001S02E06_stats_word.py @@ -12,11 +12,8 @@ def stats_text_en(text): else: n_dic[word]=n_dic[word]+1 sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) - return dict(sorted_dic) - print(dict(sorted_dic)) - #stats_text_cn 封装统计中文汉字字频的函数 @@ -33,10 +30,7 @@ def stats_text_cn(text): else: n_dic[word]=n_dic[word]+1 sorted_dic=sorted(n_dic.items(),key=lambda n_dic:n_dic[1],reverse=True) - return dict(sorted_dic) - print(dict(sorted_dic)) - diff --git a/exercises/1901100283/d09/mymodule/main.py b/exercises/1901100283/d09/mymodule/main.py new file mode 100644 index 000000000..2d2afc5e4 --- /dev/null +++ b/exercises/1901100283/d09/mymodule/main.py @@ -0,0 +1,6 @@ +from stats_word import stats_text +text=123 +try: + print(stats_text(text)) +except ValueError: + print('请重新输入字符串内容!') diff --git a/exercises/1901100283/d09/mymodule/stats_word.py b/exercises/1901100283/d09/mymodule/stats_word.py new file mode 100644 index 000000000..ebaa02ea5 --- /dev/null +++ b/exercises/1901100283/d09/mymodule/stats_word.py @@ -0,0 +1,45 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + else: + pass + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + from collections import Counter + n=int(input('请输入您需要的词频最高的前n个词的具体数值:')) + return dict(Counter(x).most_common(n)) + +#stats_text_cn 封装统计中文汉字字频的函数 +def stats_text_cn(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + a=list(text) + x=[] + for i in a: + if '\u4e00'<=i<='\u9fa5': + x.append(i) + from collections import Counter + n=int(input('请输入您需要的词频最高的前n个词的具体数值:')) + return dict(Counter(x).most_common(n)) + +#stats_text 分别调用stats_text_en , stats_text_cn ,输出合并词频统计结果 +def stats_text(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + new_dic=dict(stats_text_en(text),**stats_text_cn(text)) + return new_dic + +#读取本地文件,进行词频统计 +import json +with open(r'E:\selfteaching-python-camp\exercises\1901100283\d09\mymodule\tang300.json', 'r',encoding='utf-8') as t: + read_str=t.read() + json_list=json.loads(read_str) + print(stats_text_cn(str(json_list))) + From 86f570fcccda88a01ed309b62fe91d3c3fceda6a Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Wed, 4 Sep 2019 06:02:28 +0800 Subject: [PATCH 11/15] Day10 Homewrok --- exercises/1901100283/d10/mymodule/main.py | 6 +++ .../1901100283/d10/mymodule/stats_word.py | 46 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 exercises/1901100283/d10/mymodule/main.py create mode 100644 exercises/1901100283/d10/mymodule/stats_word.py diff --git a/exercises/1901100283/d10/mymodule/main.py b/exercises/1901100283/d10/mymodule/main.py new file mode 100644 index 000000000..82eb80e0c --- /dev/null +++ b/exercises/1901100283/d10/mymodule/main.py @@ -0,0 +1,6 @@ +from stats_word import stats_text +text=123 +try: + print(stats_text(text)) +except ValueError: + print('请重新输入字符串内容!') \ No newline at end of file diff --git a/exercises/1901100283/d10/mymodule/stats_word.py b/exercises/1901100283/d10/mymodule/stats_word.py new file mode 100644 index 000000000..18cfc50ac --- /dev/null +++ b/exercises/1901100283/d10/mymodule/stats_word.py @@ -0,0 +1,46 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + else: + pass + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + from collections import Counter + n=int(input('请输入您需要的词频最高的前n个词的具体数值:')) + return dict(Counter(x).most_common(n)) + +#stats_text_cn 封装统计中文汉字字频的函数 +import jieba +def stats_text_cn(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + seg_list=jieba.lcut(text) + x=[] + for i in seg_list: + if '\u4e00'<=i<='\u9fa5' and len(i)>=2: + x.append(i) + from collections import Counter + n=int(input('请输入您需要的中文词长度大于等于2的词频最高的前n个词的具体数值:')) + return dict(Counter(x).most_common(n)) + +#stats_text 分别调用stats_text_en , stats_text_cn ,输出合并词频统计结果 +def stats_text(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + new_dic=dict(stats_text_en(text),**stats_text_cn(text)) + return new_dic + +#读取本地文件,进行词频统计 +import json +with open(r'E:\selfteaching-python-camp\exercises\1901100283\d10\mymodule\tang300.json', 'r',encoding='utf-8') as t: + read_str=t.read() + json_list=json.loads(read_str) + print(stats_text_cn(str(json_list))) + From b576ff15dc7357aaab6272addd6595ae0dbb16e0 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Tue, 10 Sep 2019 05:33:08 +0800 Subject: [PATCH 12/15] Day11 Homework --- exercises/1901100283/d11/mymodule/main.py | 6 +++ .../1901100283/d11/mymodule/stats_word.py | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 exercises/1901100283/d11/mymodule/main.py create mode 100644 exercises/1901100283/d11/mymodule/stats_word.py diff --git a/exercises/1901100283/d11/mymodule/main.py b/exercises/1901100283/d11/mymodule/main.py new file mode 100644 index 000000000..82eb80e0c --- /dev/null +++ b/exercises/1901100283/d11/mymodule/main.py @@ -0,0 +1,6 @@ +from stats_word import stats_text +text=123 +try: + print(stats_text(text)) +except ValueError: + print('请重新输入字符串内容!') \ No newline at end of file diff --git a/exercises/1901100283/d11/mymodule/stats_word.py b/exercises/1901100283/d11/mymodule/stats_word.py new file mode 100644 index 000000000..78616ae27 --- /dev/null +++ b/exercises/1901100283/d11/mymodule/stats_word.py @@ -0,0 +1,54 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + else: + pass + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + from collections import Counter + n=int(input('请输入您需要的词频最高的前n个词的具体数值:')) + return dict(Counter(x).most_common(n)) + +#stats_text_cn 封装统计中文汉字字频的函数 +import jieba +def stats_text_cn(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + seg_list=jieba.lcut(text) + x=[] + for i in seg_list: + if '\u4e00'<=i<='\u9fa5' and len(i)>=2: + x.append(i) + from collections import Counter + return dict(Counter(x).most_common(100)) + +#stats_text 分别调用stats_text_en , stats_text_cn ,输出合并词频统计结果 +def stats_text(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + new_dic=dict(stats_text_en(text),**stats_text_cn(text)) + return new_dic + +#通过网络请求获得网页内容,使⽤分词工具对中文字符串进行分词,统计词频,得出结果,发送给到指定的邮箱 +import getpass +sender=input('请输入发件人邮箱:') +password=getpass.getpass('输入发件人邮箱密码(可复制粘贴):') +recipient=input('请输入收件人邮箱:') + +import requests +response=requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') +from pyquery import PyQuery +document=PyQuery(response.text) +content=document('#js_content').text() +body=str(stats_text_cn(content)) + +import yagmail +yag=yagmail.SMTP(sender,password,'smtp.126.com') +yag.send(recipient,'1901100283 自学训练营学习19群 Day11 PerryZ10',body) \ No newline at end of file From 161ddb358e64028947a20c538829781f3442d44b Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Mon, 16 Sep 2019 05:32:01 +0800 Subject: [PATCH 13/15] Day 12 Homework --- exercises/1901100283/d12/mymodule/main.py | 16 ++++++ .../1901100283/d12/mymodule/stats_word.py | 54 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 exercises/1901100283/d12/mymodule/main.py create mode 100644 exercises/1901100283/d12/mymodule/stats_word.py diff --git a/exercises/1901100283/d12/mymodule/main.py b/exercises/1901100283/d12/mymodule/main.py new file mode 100644 index 000000000..0713aae2e --- /dev/null +++ b/exercises/1901100283/d12/mymodule/main.py @@ -0,0 +1,16 @@ +#将实战项⽬目1的功能包装集成到个⼈人微信 +from wxpy import * +bot = Bot() +my_friend=bot.friends() +@bot.register(my_friend,SHARING) +def get_friend_url(msg): + if isinstance(msg.type,SHARING): + import requests + response=requests.get(msg.url) + from pyquery import PyQuery + document=PyQuery(response.text) + content=document('#js_content').text() + from stats_word import stats_text_cn + body=str(stats_text_cn(content)) + msg.reply(body) +embed() \ No newline at end of file diff --git a/exercises/1901100283/d12/mymodule/stats_word.py b/exercises/1901100283/d12/mymodule/stats_word.py new file mode 100644 index 000000000..78616ae27 --- /dev/null +++ b/exercises/1901100283/d12/mymodule/stats_word.py @@ -0,0 +1,54 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + else: + pass + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + from collections import Counter + n=int(input('请输入您需要的词频最高的前n个词的具体数值:')) + return dict(Counter(x).most_common(n)) + +#stats_text_cn 封装统计中文汉字字频的函数 +import jieba +def stats_text_cn(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + seg_list=jieba.lcut(text) + x=[] + for i in seg_list: + if '\u4e00'<=i<='\u9fa5' and len(i)>=2: + x.append(i) + from collections import Counter + return dict(Counter(x).most_common(100)) + +#stats_text 分别调用stats_text_en , stats_text_cn ,输出合并词频统计结果 +def stats_text(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + new_dic=dict(stats_text_en(text),**stats_text_cn(text)) + return new_dic + +#通过网络请求获得网页内容,使⽤分词工具对中文字符串进行分词,统计词频,得出结果,发送给到指定的邮箱 +import getpass +sender=input('请输入发件人邮箱:') +password=getpass.getpass('输入发件人邮箱密码(可复制粘贴):') +recipient=input('请输入收件人邮箱:') + +import requests +response=requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') +from pyquery import PyQuery +document=PyQuery(response.text) +content=document('#js_content').text() +body=str(stats_text_cn(content)) + +import yagmail +yag=yagmail.SMTP(sender,password,'smtp.126.com') +yag.send(recipient,'1901100283 自学训练营学习19群 Day11 PerryZ10',body) \ No newline at end of file From 5e13416e020115f0bea643c7f8480bd134cffb4c Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Fri, 20 Sep 2019 06:38:51 +0800 Subject: [PATCH 14/15] Day13 Homework --- exercises/1901100283/d13/mymodule/main.py | 48 ++++++++++++++++ .../1901100283/d13/mymodule/stats_word.py | 55 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 exercises/1901100283/d13/mymodule/main.py create mode 100644 exercises/1901100283/d13/mymodule/stats_word.py diff --git a/exercises/1901100283/d13/mymodule/main.py b/exercises/1901100283/d13/mymodule/main.py new file mode 100644 index 000000000..3cde393f9 --- /dev/null +++ b/exercises/1901100283/d13/mymodule/main.py @@ -0,0 +1,48 @@ +#将实战项⽬目1的功能包装集成到个⼈人微信 +'''from wxpy import * +bot = Bot() +my_friend=bot.friends() +@bot.register(my_friend,SHARING) +def get_friend_url(msg): + if isinstance(msg.type,SHARING): + import requests + response=requests.get(msg.url) + from pyquery import PyQuery + document=PyQuery(response.text) + content=document('#js_content').text() + from stats_word import stats_text_cn + body=str(stats_text_cn(content)) + msg.reply(body) +embed() +''' +#Day11作业转化成图表 +import requests +response=requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') +from pyquery import PyQuery +document=PyQuery(response.text) +content=document('#js_content').text() + +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.ticker import FuncFormatter +from pylab import mpl +mpl.rcParams['font.sans-serif']=['Microsoft YaHei'] + +from stats_word import stats_text_cn +data=stats_text_cn(content) +group_data=list(data.values()) +group_names=list(data.keys()) + +plt.rcParams.update({'figure.autolayout':True}) +fig,ax=plt.subplots() +ax.barh(group_names,group_data) +plt.style.use('seaborn-paper') +labels=ax.get_xticklabels() +plt.setp(labels,horizontalalignment='right') +ax.set(xlabel='词频',ylabel='中文汉字',title='中文汉字词频统计') +plt.show() + + + + + diff --git a/exercises/1901100283/d13/mymodule/stats_word.py b/exercises/1901100283/d13/mymodule/stats_word.py new file mode 100644 index 000000000..fbb009f6b --- /dev/null +++ b/exercises/1901100283/d13/mymodule/stats_word.py @@ -0,0 +1,55 @@ +#stats_text_en 封装统计英文单词词频的函数 +def stats_text_en(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + else: + pass + a=text.split() + x=[] + for i in a: + if i.isalpha() is True: + x.append(i) + from collections import Counter + n=int(input('请输入您需要的词频最高的前n个词的具体数值:')) + return dict(Counter(x).most_common(n)) + +#stats_text_cn 封装统计中文汉字字频的函数 +import jieba +def stats_text_cn(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + seg_list=jieba.lcut(text) + x=[] + for i in seg_list: + if '\u4e00'<=i<='\u9fa5' and len(i)>=2: + x.append(i) + from collections import Counter + return dict(Counter(x).most_common(20)) + +#stats_text 分别调用stats_text_en , stats_text_cn ,输出合并词频统计结果 +def stats_text(text): + if isinstance(text,str) is False: + print('您输入的内容不是字符串类型!') + raise ValueError + new_dic=dict(stats_text_en(text),**stats_text_cn(text)) + return new_dic + +if __name__=='__main__': +#通过网络请求获得网页内容,使⽤分词工具对中文字符串进行分词,统计词频,得出结果,发送给到指定的邮箱 + import getpass + sender=input('请输入发件人邮箱:') + password=getpass.getpass('输入发件人邮箱密码(可复制粘贴):') + recipient=input('请输入收件人邮箱:') + + import requests + response=requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') + from pyquery import PyQuery + document=PyQuery(response.text) + content=document('#js_content').text() + body=str(stats_text_cn(content)) + + import yagmail + yag=yagmail.SMTP(sender,password,'smtp.126.com') + yag.send(recipient,'1901100283 自学训练营学习19群 Day11 PerryZ10',body) \ No newline at end of file From 4026bab8d2c38dd6a707b39d78fe43936b5667f5 Mon Sep 17 00:00:00 2001 From: PerryZ10 <53920292+PerryZ10@users.noreply.github.com> Date: Sun, 22 Sep 2019 12:33:42 +0800 Subject: [PATCH 15/15] Day 14 Homework --- exercises/1901100283/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/exercises/1901100283/README.md b/exercises/1901100283/README.md index e69de29bb..f40a59256 100644 --- a/exercises/1901100283/README.md +++ b/exercises/1901100283/README.md @@ -0,0 +1,16 @@ +###ѧѵӪ-Python14ܽ +####ôſΣ +2018һżȻ֪PythonѧϰȸǰѧϰPythonҪôоѧķǺأҪôֻʵ٣ûϵͳԣն;Ϸ +2019ij˷ˡƸ֮·Ȿ飬ᵽѾü飬ÿθ̶кܴջһֵöϺüضDZ飬ԹҲĶû뵽ԴӿⱾ͸оͣһһ飬Ŀǰڿı顣ܰⱾеÿһ㶼ԼȥʵDZضһdz˲ĸ˳ɳⱾȻĹעЦʦļںšʦ֯Python̿γ̣۸񲻷ơʱ֪ѧϰPythonڼ۸Ϲûμӡ +201988գڹ˾һλƹʦͨйPython˵ӴУѧϰPythonĴѧҵձҵ˷dzõĹ˾н28000Ԫһ¡ϢҸе̫ˣҹ10ˮƽԶһѧҵô߹ʣѡҵרҵзdzĹϵδƴҶ֪˹ܡѧϰݷ򡣼ȻˣʲôɲѧϰؼΪ׼أһ죬ҹϱˡPython14šܷ2000ԪĿγ̣ҲǵһαôΡһ·оҪθһdzش壬ԼòУҪ˭ҲҾ͸˭ͣĸо +####ѧ͸ + ſγ̺κܲͬĴˣܽĵٱҪ֪ʶ1GithubЭƽ̨ 2Anaconda 3̻﷨ 4⡣ + γ̵ʦƸдѧһ׷ÿҵеIJοϾѧݣҪύҵʵݣѧϰʼԼܽ븴̣ҵƵٴѧϰͱȶԵḶ́Ⱥһѧϰ൱Ӫһѧϰ罻ѧĸˣʲôֱ̡γõķdzһѧһ׷ + йPythonܽ¼ +ǷdzϽһѧʡʹһţߴСдУݲһСҪѧϰ̵ϸġľÿ˶Ӧѧϰſγ̡ +ԼҴ𰸡ѧָ̾⣬һԼҴ𰸣ҪԼһ޶ʱ䣬ʱԼܽ⣬ǾͿص˰æ +Ҫ̻֪ܶʶ㣬⺺˵ÿһ֪ʶ㣬ѧϰʱһǸҪ˼·ͻ᲻ +ͬһжֽ˼·ڿһʱ뾡ܶĽ˼·ѡһ˼·ʼ̺;Լʵ޷ʱԳĽ˼·̡ +̷dz߼ڱʱ߼ҲǷdzһҪdz̵Ĺлߺܶ· +ҪΪǺԼ޹ءÿҵɺƵ⣬ÿҲῴǿһûжԼԭȵҵ޸ĹΪԼдҲҵˡֱijһҵеģʱˣƵᵽֹһΣҵȴ벻̽ͻȻǶôֲһ£ΪֺԼ޹ص뷨ȻĴ˺üѧϰijĻᣡ +һηdzѧdzлЦʦлԼҵͬѧǣһԼȤPythonϼǰУ