From 69ac6783286e11850b8c6ed3be583be903efd9f4 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Tue, 20 Aug 2019 14:55:38 +0800 Subject: [PATCH 01/17] Create 1001S02E04_control_flow.py control_flow --- .../1901100240/1001S02E04_control_flow.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 exercises/1901100240/1001S02E04_control_flow.py diff --git a/exercises/1901100240/1001S02E04_control_flow.py b/exercises/1901100240/1001S02E04_control_flow.py new file mode 100644 index 000000000..e539ea299 --- /dev/null +++ b/exercises/1901100240/1001S02E04_control_flow.py @@ -0,0 +1,20 @@ +# This part is to print multiplication table by using the for...in loop +print("The Multiplication Table") +for i in range(1,10): + for j in range(1,i+1): + print(i,'*',j,'=',i*j,end=' ') + print('') + +print('') +# This part is to print multiplication table without even numbers by using the while loop +print('The Multiplication Table Without Even Number') +i=1; +while i<10 : + if i%2!=0: + j=1; + while j<=i: + if j%2!=0: + print(i,'*',j,'=',i*j,end=' ') + j+=1 + print("") + i+=1 \ No newline at end of file From 63b1e678cbb7a4a83de63d743bcd4e8d2473f6f4 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Tue, 20 Aug 2019 22:30:49 +0800 Subject: [PATCH 02/17] day5 submit --- .../1901100240/1001S02E04_control_flow.py | 4 ++-- exercises/1901100240/1001S02E05_array.py | 20 ++++++++++++++++ exercises/1901100240/1001S02E05_stats_text.py | 17 +++++++++++++ exercises/1901100240/1001S02E05_string.py | 24 +++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 exercises/1901100240/1001S02E05_array.py create mode 100644 exercises/1901100240/1001S02E05_stats_text.py create mode 100644 exercises/1901100240/1001S02E05_string.py diff --git a/exercises/1901100240/1001S02E04_control_flow.py b/exercises/1901100240/1001S02E04_control_flow.py index e539ea299..c126e2907 100644 --- a/exercises/1901100240/1001S02E04_control_flow.py +++ b/exercises/1901100240/1001S02E04_control_flow.py @@ -2,7 +2,7 @@ print("The Multiplication Table") for i in range(1,10): for j in range(1,i+1): - print(i,'*',j,'=',i*j,end=' ') + print(i,'*',j,'=',i*j,end='\t') print('') print('') @@ -14,7 +14,7 @@ j=1; while j<=i: if j%2!=0: - print(i,'*',j,'=',i*j,end=' ') + print(i,'*',j,'=',i*j,end='\t') j+=1 print("") i+=1 \ No newline at end of file diff --git a/exercises/1901100240/1001S02E05_array.py b/exercises/1901100240/1001S02E05_array.py new file mode 100644 index 000000000..eb11c87cc --- /dev/null +++ b/exercises/1901100240/1001S02E05_array.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 20 21:59:24 2019 + +@author: yanning +""" + +array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + +array.reverse() +str1 = ''.join(map(str,array)) + +str1 = str1[2:8] +str1 = str1[::-1] +int1 = int(str1) + +print("The binary result is ",bin(int1)) +print("The octonary result is ",oct(int1)) +print("The hexadecimal result is ",hex(int1)) diff --git a/exercises/1901100240/1001S02E05_stats_text.py b/exercises/1901100240/1001S02E05_stats_text.py new file mode 100644 index 000000000..e067ef7e2 --- /dev/null +++ b/exercises/1901100240/1001S02E05_stats_text.py @@ -0,0 +1,17 @@ +import re +text = "The Zen of Python, by Tim PetersBeautiful 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 doit.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 = re.split(r"(?:[\s,.!*?-])",text) +while '' in text: + text.remove('') + +D={} +for char in text: + if char not in D: + D[char]=1 + else: + D[char]=D[char]+1 + + +D=sorted(D.items(),key=lambda D:D[1],reverse=True) + +print(D) \ No newline at end of file diff --git a/exercises/1901100240/1001S02E05_string.py b/exercises/1901100240/1001S02E05_string.py new file mode 100644 index 000000000..10116d02e --- /dev/null +++ b/exercises/1901100240/1001S02E05_string.py @@ -0,0 +1,24 @@ +import re +text = "The Zen of Python, by Tim PetersBeautiful 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 doit.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 = re.split(r"(?:[\s,.!*?-])",text) +while '' in text: + text.remove('') + +for i in range(0,len(text)): + if text[i]=='better': + text[i]='worse' + +relist=[] +for i in range(0,len(text)): + if 'ea' in text[i]: + relist.append(text[i]) +for rem in relist: + while rem in text: + text.remove(rem) + +for i in range(0,len(text)): + text[i]=text[i].swapcase() + +text.sort() + +print(text) \ No newline at end of file From 002fa85ae0c492c07b672a927adefc775d219d6f Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Wed, 21 Aug 2019 12:47:56 +0800 Subject: [PATCH 03/17] day3 day3 --- .../1901100240/1001S02E02_hello_python.py | 6 ++- exercises/1901100240/1001S02E03_calculator.py | 41 ++++++++++++----- .../1901100240/1001S02E04_control_flow.py | 32 ++++++------- exercises/1901100240/1001S02E05_array.py | 25 ++++------- exercises/1901100240/1001S02E05_stats_text.py | 18 +++++--- exercises/1901100240/1001S02E05_string.py | 15 +++++-- exercises/1901100240/1001S02E06_stats_word.py | 45 +++++++++++++++++++ 7 files changed, 129 insertions(+), 53 deletions(-) create mode 100644 exercises/1901100240/1001S02E06_stats_word.py diff --git a/exercises/1901100240/1001S02E02_hello_python.py b/exercises/1901100240/1001S02E02_hello_python.py index e75154b7c..f5ac8cc6d 100644 --- a/exercises/1901100240/1001S02E02_hello_python.py +++ b/exercises/1901100240/1001S02E02_hello_python.py @@ -1 +1,5 @@ -print("hello world") \ No newline at end of file +print('Hello','World!') #默认单词用空格隔开 (Defautly seperate by space) + +print('Hello','world', sep=' ', end='\n') #空格隔开,"\n"换行 (Seperate by space, '\n' start a new line) + +print('Hello','world', sep='~', end='\t') #'~'隔开,'\t'空两个 (Seperate by '~', '\t' adding two blank at the end) \ No newline at end of file diff --git a/exercises/1901100240/1001S02E03_calculator.py b/exercises/1901100240/1001S02E03_calculator.py index 389f7d182..416699cb1 100644 --- a/exercises/1901100240/1001S02E03_calculator.py +++ b/exercises/1901100240/1001S02E03_calculator.py @@ -1,41 +1,60 @@ +# This is a simple calculator can only calculate four basic algorithm print("This is a designed calculator") -# THis part is to collect the input of numbers and operations. And report error if the input is illegal +# THis part is to collect the input of numbers and operations +# Report error if the input is illegal by using try and except +# While loop will not stop until enter a ligal statement while True: + # Restrict the input in form of float or int try: - a=float(input("Please enter the first number")) + a=float(input("Please enter the first number: ")) break + # Provide a feed back and ask for re enter except ValueError: print("Error! You should enter a numbenr!") while True: - b=input("Enter the operation you want do. Type in one of the '+', '-', '*', '/'") + # Restrict the input in form of +, -, *, / + b=input('''Please type in the operation you want to complete: + + for addition + - for subtraction + * for multiplication + / for division + ''') + # Break the loop if input is legal if b in ['+','-','*','/']: break + # Provide the feedback if input is illegal else: print("Error! You should type in one of '+', '-', '*', '/'") +# Check the legality for the second input number while True: try: - c=float(input("Please enter the second number")) + c=float(input("Please enter the second number: ")) break except ValueError: print("Error! You should enter a numbenr!") -# This part is doing the calculation by checking the value of b. +# Doing the calculation by combining the imformation in a, b, c +# For addition case if b=='+': - print("The result of calculation is ", a+c) + print("The result of calculation is: \n", a,' + ',c,' = ',a+c) +# For subtraction case elif b=='-': - print("The result of calculation is ", a-c) + print("The result of calculation is ", a,' - ',c,' = ',a-c) +# For multiplication case elif b=='*': - print("The result of calculation is ", a*c) -elif b=='/': # This part is doing the division and dealing with the ZeroDivision Error. - while c==0: + print("The result of calculation is ", a,' * ',c,' = ',a*c) +# For division case +elif b=='/': + while c==0: # Check if the denominator is zero print("Error! The denominator can't be zero, this will cause a ZeroDivision Error!") + # Ask for new denominator number while True: try: c=float(input("Please enter the second number")) break except ValueError: print("Error! You should enter a numbenr!") - print("The result of calculation is ", a/c) + print("The result of calculation is ", a,' / ',c,' = ', a/c) \ No newline at end of file diff --git a/exercises/1901100240/1001S02E04_control_flow.py b/exercises/1901100240/1001S02E04_control_flow.py index c126e2907..75afb1a7e 100644 --- a/exercises/1901100240/1001S02E04_control_flow.py +++ b/exercises/1901100240/1001S02E04_control_flow.py @@ -1,20 +1,20 @@ -# This part is to print multiplication table by using the for...in loop +# Print multiplication table by using the for...in loop print("The Multiplication Table") -for i in range(1,10): - for j in range(1,i+1): - print(i,'*',j,'=',i*j,end='\t') - print('') - +for i in range(1,10): # The row start from 1 to 9 + for j in range(1,i+1): # The column start from 1 to i + print(i,'*',j,'=',i*j,end='\t') # \t to make double blank + print('') # Start a new line for each row i print('') -# This part is to print multiplication table without even numbers by using the while loop + + +# Print multiplication table without even numbers by using the while loop print('The Multiplication Table Without Even Number') -i=1; -while i<10 : - if i%2!=0: - j=1; - while j<=i: - if j%2!=0: - print(i,'*',j,'=',i*j,end='\t') - j+=1 - print("") +i=1 # The row start from 1 +while i <= 9 : # Loop the row from 1 to 9 + if i%2 != 0: # Filter the even row + j = 1 # The column start from 1 + while j <= i: # Loop the column from 1 to i + print(i,'*',j,'=',i*j,end='\t') # \t to make double blank + j += 1 + print("") # Start a new line for each odd row i+=1 \ No newline at end of file diff --git a/exercises/1901100240/1001S02E05_array.py b/exercises/1901100240/1001S02E05_array.py index eb11c87cc..39b5a56fc 100644 --- a/exercises/1901100240/1001S02E05_array.py +++ b/exercises/1901100240/1001S02E05_array.py @@ -1,20 +1,13 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Tue Aug 20 21:59:24 2019 - -@author: yanning -""" - +# This algorithm is just show couple feature of list and string array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -array.reverse() -str1 = ''.join(map(str,array)) +array.reverse() # Reverse the list +str1 = ''.join(map(str,array)) # Transform the list to string -str1 = str1[2:8] -str1 = str1[::-1] -int1 = int(str1) +str1 = str1[2:8] # Cut the string from the third to the eighth element +str1 = str1[::-1] # Reverse the order +int1 = int(str1) # Transfer to the type integer -print("The binary result is ",bin(int1)) -print("The octonary result is ",oct(int1)) -print("The hexadecimal result is ",hex(int1)) +print("The binary result is ",bin(int1)) # Transfer to binary system +print("The octonary result is ",oct(int1)) # Transfer to octonary system +print("The hexadecimal result is ",hex(int1)) # Transfer to hexadecimal system diff --git a/exercises/1901100240/1001S02E05_stats_text.py b/exercises/1901100240/1001S02E05_stats_text.py index e067ef7e2..d566c5b7d 100644 --- a/exercises/1901100240/1001S02E05_stats_text.py +++ b/exercises/1901100240/1001S02E05_stats_text.py @@ -1,17 +1,23 @@ +# This algorithm uses dictionary to count and sort the word in the text import re +import string text = "The Zen of Python, by Tim PetersBeautiful 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 doit.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 = re.split(r"(?:[\s,.!*?-])",text) + +# Use re.split to split the string into list +text = re.split(r"(?:[\s!#$%&\*+,-./:;<=>?@^_`{|}~])",text) #[] sperate the multiple symbol, \s serate the space, ?: exclude the symbol from the list +# Remove all the empty element in the list while '' in text: text.remove('') -D={} +D={} # Create empty dictionary +# Count the word use dictionary for char in text: - if char not in D: + if char not in D: # Set the word to 1 if the word not yet in dictionary D[char]=1 - else: - D[char]=D[char]+1 - + else: # The count plus 1 if the word already in dictionary + D[char]+=1 +# Sorted the dictionary by value in decreasing order D=sorted(D.items(),key=lambda D:D[1],reverse=True) print(D) \ No newline at end of file diff --git a/exercises/1901100240/1001S02E05_string.py b/exercises/1901100240/1001S02E05_string.py index 10116d02e..ffe10422d 100644 --- a/exercises/1901100240/1001S02E05_string.py +++ b/exercises/1901100240/1001S02E05_string.py @@ -1,24 +1,33 @@ +# This algorithm allowed us take any text input in string form, seperate them into single words and sorted by alphabet order import re text = "The Zen of Python, by Tim PetersBeautiful 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 doit.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 = re.split(r"(?:[\s,.!*?-])",text) + +# Use re.split to split the string into list +text = re.split(r"(?:[\s,.!*?-])",text) #[] sperate the multiple symbol, \s serate the space, () exclude the symbol from the list +# Remove all the empty element in the list while '' in text: text.remove('') +# Replace all the 'better' element by 'worse' for i in range(0,len(text)): if text[i]=='better': text[i]='worse' -relist=[] +relist=[] # Create a list to store the word include 'ea' +# Check all the element and store the element with 'ea' into the list for i in range(0,len(text)): if 'ea' in text[i]: relist.append(text[i]) +# Remove the element in the relist from the origin list for rem in relist: while rem in text: text.remove(rem) +# Swap the uppercase and lowercase for each element for i in range(0,len(text)): text[i]=text[i].swapcase() - + +# Sort the list by alphabet order text.sort() print(text) \ No newline at end of file diff --git a/exercises/1901100240/1001S02E06_stats_word.py b/exercises/1901100240/1001S02E06_stats_word.py new file mode 100644 index 000000000..dc793208c --- /dev/null +++ b/exercises/1901100240/1001S02E06_stats_word.py @@ -0,0 +1,45 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +import re +# Define the function +def stats_text_en(en_text): + # Split the en_text into single words and put them into a list + en_text=re.split(r"(?:[\s!#$%&\*+,-./:;<=>?@^_`{|}~])",en_text) #[] sperate the multiple symbol, \s serate the space, ?: exclude the symbol from the list + # Remove all the empty element from the list + while '' in en_text: + en_text.remove('') + # Count the word use dictionary + en_count={} # Create an empty dictionary + for char in en_text: + if char not in en_count: # Set the value of word to 1 if the word not yet in dictionary + en_count[char] = 1 + else: # The count plus 1 if the word already in dictionary + en_count[char] += 1 + # Sorted the dictionary by value in decreasing order + en_count = sorted(en_count.items(), key = lambda en_count:en_count[1], reverse = True) + return en_count # Return the dictionary as result + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every single character +def stats_text_cn(cn_text): + cn_text=list(cn_text) # Transfer the cn_text to list + # Remove all the special symbol element from the list + for symbol in "!“”#$%&‘’()*+,-。/:;、……<=>?@[]《》^_`{|}~\n": + while symbol in cn_text: # Remove the element from list as long as it is a special symbol + cn_text.remove(symbol) + # Count the word use dictionary + cn_count={} # Create an empty dictionary + for char in cn_text: + if char not in cn_count: # Set the value of word to 1 if the word not yet in dictionary + cn_count[char] = 1 + else: # The count plus 1 if the word already in dictionary + cn_count[char] += 1 + # Sorted the dictionary by value in decreasing order + cn_count = sorted(cn_count.items(), key = lambda cn_count:cn_count[1], reverse = True) + return cn_count # Return the dictionary as result + +en_string = "The Zen of Python, by Tim PetersBeautiful 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 doit.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_string='''我冒着严寒,回到相隔二千余里,别了二十余年的故乡去。时候既然是深冬;渐近故乡时,天气又阴晦了,冷风吹进船舱中,呜呜的响,从篷隙向外一望,苍黄的天底下,远近横着几个萧索的荒村,没有一些活气。我的心禁不住悲凉起来了。阿!这不是我二十年来时时记得的故乡?我所记得的故乡全不如此。我的故乡好得多了。但要我记起他的美丽,说出他的佳处来,却又没有影像,没有言辞了。仿佛也就如此。于是我自己解释说:故乡本也如此,——虽然没有进步,也未必有如我所感的悲凉,这只是我自己心情的改变罢了,因为我这次回乡,本没有什么好心绪。''' + +print(stats_text_en(en_string)) +print(stats_text_cn(cn_string)) \ No newline at end of file From 8f968c61191489f3fe31b103f0ecddeba31a665f Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Wed, 21 Aug 2019 15:44:29 +0800 Subject: [PATCH 04/17] day07 day07 --- exercises/1901100240/d07/mymodule/main.py | 66 +++++++++++++++++++ .../1901100240/d07/mymodule/stats_word.py | 47 +++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 exercises/1901100240/d07/mymodule/main.py create mode 100644 exercises/1901100240/d07/mymodule/stats_word.py diff --git a/exercises/1901100240/d07/mymodule/main.py b/exercises/1901100240/d07/mymodule/main.py new file mode 100644 index 000000000..d8ef2e2db --- /dev/null +++ b/exercises/1901100240/d07/mymodule/main.py @@ -0,0 +1,66 @@ +import stats_word + +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("The Statistic of English Words \n", stats_word.stats_text(text)[0]) +print("") +print("The Statistic of Chinese Charactor \n", stats_word.stats_text(text)[1]) \ No newline at end of file diff --git a/exercises/1901100240/d07/mymodule/stats_word.py b/exercises/1901100240/d07/mymodule/stats_word.py new file mode 100644 index 000000000..a564e3b92 --- /dev/null +++ b/exercises/1901100240/d07/mymodule/stats_word.py @@ -0,0 +1,47 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +import re +# Define the function +def stats_text_en(en_text): + # Split the en_text into single words and put them into a list + en_text=re.split(r"(?:[\s!#$%&\*+,-./:;<=>?@^_`{|}~])",en_text) #[] sperate the multiple symbol, \s serate the space, ?: exclude the symbol from the list + # Remove all the empty element from the list + while '' in en_text: + en_text.remove('') + # Count the word use dictionary + en_count={} # Create an empty dictionary + for char in en_text: + if char not in en_count: # Set the value of word to 1 if the word not yet in dictionary + en_count[char] = 1 + else: # The count plus 1 if the word already in dictionary + en_count[char] += 1 + # Sorted the dictionary by value in decreasing order + en_count = sorted(en_count.items(), key = lambda en_count:en_count[1], reverse = True) + return en_count # Return the dictionary as result + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every single character +def stats_text_cn(cn_text): + cn_text=list(cn_text) # Transfer the cn_text to list + # Remove all the special symbol element from the list + for symbol in "!“”#$%&‘’()*+,-。/:;、……<=>?@[]《》^_`{|}~\n": + while symbol in cn_text: # Remove the element from list as long as it is a special symbol + cn_text.remove(symbol) + # Count the word use dictionary + cn_count={} # Create an empty dictionary + for char in cn_text: + if char not in cn_count: # Set the value of word to 1 if the word not yet in dictionary + cn_count[char] = 1 + else: # The count plus 1 if the word already in dictionary + cn_count[char] += 1 + # Sorted the dictionary by value in decreasing order + cn_count = sorted(cn_count.items(), key = lambda cn_count:cn_count[1], reverse = True) + return cn_count # Return the dictionary as result + +# This function uses the following encoding: utf-8 +# Return a list of strings with English and Chinese words seperatly +def stats_text(string): + # Seperate the Chinese and English words into two strings by checking ASCII value + en_text = "".join(i for i in string if ord(i) < 256).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + cn_text = "".join(j for j in string if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + return [stats_text_en(en_text),stats_text_cn(cn_text)] From 2997aa4b62c68bb6265f7f45c1fda86bccaa44b8 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Wed, 21 Aug 2019 16:33:53 +0800 Subject: [PATCH 05/17] try and exception day08 --- exercises/1901100240/d08/mymodule/main.py | 69 +++++++++++++++++++ .../1901100240/d08/mymodule/stats_word.py | 56 +++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 exercises/1901100240/d08/mymodule/main.py create mode 100644 exercises/1901100240/d08/mymodule/stats_word.py diff --git a/exercises/1901100240/d08/mymodule/main.py b/exercises/1901100240/d08/mymodule/main.py new file mode 100644 index 000000000..e6208c5ef --- /dev/null +++ b/exercises/1901100240/d08/mymodule/main.py @@ -0,0 +1,69 @@ +import stats_word + +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. +''' + +stats_word.stats_text(100) +stats_word.stats_text(True) +stats_word.stats_text_cn(230) +stats_word.stats_text_cn(False) +stats_word.stats_text_en(300) +stats_word.stats_text_en(False) \ No newline at end of file diff --git a/exercises/1901100240/d08/mymodule/stats_word.py b/exercises/1901100240/d08/mymodule/stats_word.py new file mode 100644 index 000000000..5bcf6f6f0 --- /dev/null +++ b/exercises/1901100240/d08/mymodule/stats_word.py @@ -0,0 +1,56 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +import re +# Define the function +def stats_text_en(en_text): + # Split the en_text into single words and put them into a list + try: + en_text=re.split(r"(?:[\s!#$%&\*+,-./:;<=>?@^_`{|}~])",en_text) #[] sperate the multiple symbol, \s serate the space, ?: exclude the symbol from the list + # Remove all the empty element from the list + while '' in en_text: + en_text.remove('') + # Count the word use dictionary + en_count={} # Create an empty dictionary + for char in en_text: + if char not in en_count: # Set the value of word to 1 if the word not yet in dictionary + en_count[char] = 1 + else: # The count plus 1 if the word already in dictionary + en_count[char] += 1 + # Sorted the dictionary by value in decreasing order + en_count = sorted(en_count.items(), key = lambda en_count:en_count[1], reverse = True) + return en_count # Return the dictionary as result + except TypeError: + print("Error! The input of function stats_text_en should be the form of string. The input now is in ", type(en_text)," type. Please retry and enter a string") + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every single character +def stats_text_cn(cn_text): + try: + cn_text=list(cn_text) # Transfer the cn_text to list + # Remove all the special symbol element from the list + for symbol in "!“”#$%&‘’()*+,-。/:;、……<=>?@[]《》^_`{|}~\n": + while symbol in cn_text: # Remove the element from list as long as it is a special symbol + cn_text.remove(symbol) + # Count the word use dictionary + cn_count={} # Create an empty dictionary + for char in cn_text: + if char not in cn_count: # Set the value of word to 1 if the word not yet in dictionary + cn_count[char] = 1 + else: # The count plus 1 if the word already in dictionary + cn_count[char] += 1 + # Sorted the dictionary by value in decreasing order + cn_count = sorted(cn_count.items(), key = lambda cn_count:cn_count[1], reverse = True) + return cn_count # Return the dictionary as result + except TypeError: + print("Error! The input of function stats_text_cn should be the form of string. The input now is in ", type(cn_text)," type. Please retry and enter a string") + +# This function uses the following encoding: utf-8 +# Return a list of strings with English and Chinese words seperatly +def stats_text(string): + # Seperate the Chinese and English words into two strings by checking ASCII value + try: + en_text = "".join(i for i in string if ord(i) < 256).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + cn_text = "".join(j for j in string if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + return [stats_text_en(en_text),stats_text_cn(cn_text)] + except TypeError: + print("Error! The input of function stats_text should be the form of string. The input now is in ", type(string)," type. Please retry and enter a string") From 178fe0889198358c402eb3b80b99532dfc3a95a6 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Wed, 21 Aug 2019 23:36:17 +0800 Subject: [PATCH 06/17] statistic of tang300 day09 --- exercises/1901100240/d09/mymodule/main.py | 20 ++++++++++ .../1901100240/d09/mymodule/stats_word.py | 39 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 exercises/1901100240/d09/mymodule/main.py create mode 100644 exercises/1901100240/d09/mymodule/stats_word.py diff --git a/exercises/1901100240/d09/mymodule/main.py b/exercises/1901100240/d09/mymodule/main.py new file mode 100644 index 000000000..449c17965 --- /dev/null +++ b/exercises/1901100240/d09/mymodule/main.py @@ -0,0 +1,20 @@ +# This algorithm is to do the statistic of frequency of Chinese characters in tang300 +# Using the user-defined algrorithm 'stats_word' and package 'json' +import stats_word +import json + +# Imput the tang300.json documents and transfer into form of [{dict},{dict},{dict}] +with open('/Users/yanning/Documents/GitHub/selfteaching-python-camp/exercises/1901100240/d09/mymodule/tang300.json','r+',encoding = "utf-8") as f: + tang_load = json.load(f) + +# Create a empty string and use it as storage. +tang_text="" +# Using loop to combine all dict.values() into the storage string +for unit in tang_load: # Unit will be each dictionary in the list + for char in unit.values(): # Char will be each values of the dictionary in form ['values','values','values','values'] + for content in str(char): # content will be each element in the list Char + if ord(content) > 256 and content not in "!“”#$%&‘’()*+,-。/:;、……<=>?@[]《》^_`{|}~\n": # Only count the Chinese characters without any symbol + tang_text += str(content) # Store the string into the storage string tang_text + +# Doing the statistic of frequncy of each Chinese characters and make it a dictionary +print(stats_word.stats_text(tang_text,100)) diff --git a/exercises/1901100240/d09/mymodule/stats_word.py b/exercises/1901100240/d09/mymodule/stats_word.py new file mode 100644 index 000000000..b8f61cbae --- /dev/null +++ b/exercises/1901100240/d09/mymodule/stats_word.py @@ -0,0 +1,39 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +from collections import Counter +# Define the function +def stats_text_en(en_text,count): + try: + en_text = "".join(i for i in en_text if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + # Count the word use Counter + try: + en_count = Counter(en_text).most_common(count) # Create an counter + return en_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_en should be the form of integer. The input now is in ", type(en_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_en should be the form of string. The input now is in ", type(en_text)," type. Please retry and enter a string") + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every single character +def stats_text_cn(cn_text,count): + try: + cn_text = "".join(j for j in cn_text if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + try: + cn_count = Counter(cn_text).most_common(count) # Create an counter + return cn_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_cn should be the form of integer. The input now is in ", type(cn_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_cn should be the form of string. The input now is in ", type(cn_text)," type. Please retry and enter a string") + +# This function uses the following encoding: utf-8 +# Return a list of strings with English and Chinese words seperatly +def stats_text(string,count): + # Seperate the Chinese and English words into two strings by checking ASCII value + try: + en_text = "".join(i for i in string if ord(i) < 256).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + cn_text = "".join(j for j in string if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + return [stats_text_en(en_text,count),stats_text_cn(cn_text,count)] + except TypeError: + print("Error! The first input of function stats_text should be the form of string. The input now is in ", type(string)," type. Please retry and enter a string") From d3a012a5cc0f47f0affd25a96a3a02f258075242 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Wed, 28 Aug 2019 17:55:28 +0800 Subject: [PATCH 07/17] jieba usage day 10 --- exercises/1901100240/d09/mymodule/main.py | 9 ++-- exercises/1901100240/d10/mymodule/main.py | 20 ++++++++ .../1901100240/d10/mymodule/stats_word.py | 48 +++++++++++++++++++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 exercises/1901100240/d10/mymodule/main.py create mode 100644 exercises/1901100240/d10/mymodule/stats_word.py diff --git a/exercises/1901100240/d09/mymodule/main.py b/exercises/1901100240/d09/mymodule/main.py index 449c17965..e2cf96363 100644 --- a/exercises/1901100240/d09/mymodule/main.py +++ b/exercises/1901100240/d09/mymodule/main.py @@ -2,9 +2,10 @@ # Using the user-defined algrorithm 'stats_word' and package 'json' import stats_word import json +import os # Imput the tang300.json documents and transfer into form of [{dict},{dict},{dict}] -with open('/Users/yanning/Documents/GitHub/selfteaching-python-camp/exercises/1901100240/d09/mymodule/tang300.json','r+',encoding = "utf-8") as f: +with open('Documents/GitHub/selfteaching-python-camp/exercises/1901100240/d09/mymodule/tang300.json','r+',encoding = "utf-8") as f: tang_load = json.load(f) # Create a empty string and use it as storage. @@ -13,8 +14,8 @@ for unit in tang_load: # Unit will be each dictionary in the list for char in unit.values(): # Char will be each values of the dictionary in form ['values','values','values','values'] for content in str(char): # content will be each element in the list Char - if ord(content) > 256 and content not in "!“”#$%&‘’()*+,-。/:;、……<=>?@[]《》^_`{|}~\n": # Only count the Chinese characters without any symbol + if ord(content) > 256 and content not in "!“”#$%&‘’()*+,-。/:;、……<=>?@[][]《》^_`{|}~\n": # Only count the Chinese characters without any symbol tang_text += str(content) # Store the string into the storage string tang_text -# Doing the statistic of frequncy of each Chinese characters and make it a dictionary -print(stats_word.stats_text(tang_text,100)) +# Doing the statistic of frequncy of each Chinese characters and make it a list +print(stats_word.stats_text_cn(tang_text,100)) \ No newline at end of file diff --git a/exercises/1901100240/d10/mymodule/main.py b/exercises/1901100240/d10/mymodule/main.py new file mode 100644 index 000000000..3964d3018 --- /dev/null +++ b/exercises/1901100240/d10/mymodule/main.py @@ -0,0 +1,20 @@ +# This algorithm is to do the statistic of frequency of Chinese characters in tang300 +# Using the user-defined algrorithm 'stats_word' and package 'json' +import stats_word +import json + +# Imput the tang300.json documents and transfer into form of [{dict},{dict},{dict}] +with open('/Users/yanning/Documents/GitHub/selfteaching-python-camp/exercises/1901100240/d10/mymodule/tang300.json','r+',encoding = "utf-8") as f: + tang_load = json.load(f) + +# Create a empty string and use it as storage. +tang_text="" +# Using loop to combine all dict.values() into the storage string +for unit in tang_load: # Unit will be each dictionary in the list + for char in unit.values(): # Char will be each values of the dictionary in form ['values','values','values','values'] + for content in str(char): # content will be each element in the list Char + if ord(content) > 256 and content not in "!“”#$%&‘’()*+,-。/:;、……<=>?@[][]《》^_`{|}~\n": # Only count the Chinese characters without any symbol + tang_text += str(content) # Store the string into the storage string tang_text + +# Doing the statistic of frequncy of each Chinese characters and make it a list +print(stats_word.stats_text_cn(tang_text,20)) \ No newline at end of file diff --git a/exercises/1901100240/d10/mymodule/stats_word.py b/exercises/1901100240/d10/mymodule/stats_word.py new file mode 100644 index 000000000..dd30d6657 --- /dev/null +++ b/exercises/1901100240/d10/mymodule/stats_word.py @@ -0,0 +1,48 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +from collections import Counter +import jieba + +# Define the function +def stats_text_en(en_text,count): + try: + en_text = "".join(i for i in en_text if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + # Count the word use Counter + try: + en_count = Counter(en_text).most_common(count) # Create an counter + return en_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_en should be the form of integer. The input now is in ", type(en_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_en should be the form of string. The input now is in ", type(en_text)," type. Please retry and enter a string") + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every Chinese word using algrothm jieba +def stats_text_cn(cn_text,count): + try: + cn_text = "".join(j for j in cn_text if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + # Seprate the words in cn_text + cn_list=jieba.cut(cn_text,cut_all=False) + # Selected the words which length greater than two + cn_two_list=[] + for unit in cn_list: + if len(unit) >= 2: + cn_two_list.append(unit) + try: + cn_count = Counter(cn_two_list).most_common(count) # Create an counter + return cn_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_cn should be the form of integer. The input now is in ", type(cn_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_cn should be the form of string. The input now is in ", type(cn_text)," type. Please retry and enter a string") + +# This function uses the following encoding: utf-8 +# Return a list of strings with English and Chinese words seperatly +def stats_text(string,count): + # Seperate the Chinese and English words into two strings by checking ASCII value + try: + en_text = "".join(i for i in string if ord(i) < 256).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + cn_text = "".join(j for j in string if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + return [stats_text_en(en_text,count),stats_text_cn(cn_text,count)] + except TypeError: + print("Error! The first input of function stats_text should be the form of string. The input now is in ", type(string)," type. Please retry and enter a string") From b2d8fe20c36c23db4724d6208da10f79effbd592 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Thu, 29 Aug 2019 14:12:13 +0800 Subject: [PATCH 08/17] d11 try d11 try --- .../1901100240/1001S02E04_control_flow.py | 29 +---------- exercises/1901100240/d11/mymodule/main.py | 25 ++++++++++ .../1901100240/d11/mymodule/stats_word.py | 48 +++++++++++++++++++ 3 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 exercises/1901100240/d11/mymodule/main.py create mode 100644 exercises/1901100240/d11/mymodule/stats_word.py diff --git a/exercises/1901100240/1001S02E04_control_flow.py b/exercises/1901100240/1001S02E04_control_flow.py index bd8c6079e..caf9e54a2 100644 --- a/exercises/1901100240/1001S02E04_control_flow.py +++ b/exercises/1901100240/1001S02E04_control_flow.py @@ -5,20 +5,8 @@ for j in range(1,i+1): # The column start from 1 to i print(i,'*',j,'=',i*j,end='\t') # \t to make double blank print('') # Start a new line for each row i - -for i in range(1,10): - for j in range(1,i+1): - - print(i,'*',j,'=',i*j,end='\t') - - print(i,'*',j,'=',i*j,end=' ') - - print('') - - print('') - # Print multiplication table without even numbers by using the while loop print('The Multiplication Table Without Even Number') @@ -30,19 +18,4 @@ print(i,'*',j,'=',i*j,end='\t') # \t to make double blank j += 1 print("") # Start a new line for each odd row - -i=1; -while i<10 : - if i%2!=0: - j=1; - while j<=i: - if j%2!=0: - - print(i,'*',j,'=',i*j,end='\t') - - print(i,'*',j,'=',i*j,end=' ') - - j+=1 - print("") - - i+=1 \ No newline at end of file + i += 1 \ No newline at end of file diff --git a/exercises/1901100240/d11/mymodule/main.py b/exercises/1901100240/d11/mymodule/main.py new file mode 100644 index 000000000..bedafc7f9 --- /dev/null +++ b/exercises/1901100240/d11/mymodule/main.py @@ -0,0 +1,25 @@ +import requests +from pyquery import PyQuery +import stats_word +import getpass +import yagmail + +response=requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') +document = PyQuery(response.text) +content = document('#js_content').text() +stats = stats_word.stats_text_cn(content,100) +string=str('') +for unit in stats: + if len(unit[0]) <= 2: + string += "'" + unit[0] + "'的频率是: " + str(unit[1]) + "\n" + elif len(unit[0]) == 3: + string += "'" + unit[0] + "'的频率是: " + str(unit[1]) + "\n" + +sender = 'yanning931231@sina.com' +password = '7c50817e1ffff142' +recipients = '604332298@qq.com' +print(type(sender)) +yag = yagmail.SMTP(sender,password) +print(type(password)) +yag.send(to=recipients,subject='[你好]',contents=string) +print('done') \ No newline at end of file diff --git a/exercises/1901100240/d11/mymodule/stats_word.py b/exercises/1901100240/d11/mymodule/stats_word.py new file mode 100644 index 000000000..dd30d6657 --- /dev/null +++ b/exercises/1901100240/d11/mymodule/stats_word.py @@ -0,0 +1,48 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +from collections import Counter +import jieba + +# Define the function +def stats_text_en(en_text,count): + try: + en_text = "".join(i for i in en_text if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + # Count the word use Counter + try: + en_count = Counter(en_text).most_common(count) # Create an counter + return en_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_en should be the form of integer. The input now is in ", type(en_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_en should be the form of string. The input now is in ", type(en_text)," type. Please retry and enter a string") + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every Chinese word using algrothm jieba +def stats_text_cn(cn_text,count): + try: + cn_text = "".join(j for j in cn_text if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + # Seprate the words in cn_text + cn_list=jieba.cut(cn_text,cut_all=False) + # Selected the words which length greater than two + cn_two_list=[] + for unit in cn_list: + if len(unit) >= 2: + cn_two_list.append(unit) + try: + cn_count = Counter(cn_two_list).most_common(count) # Create an counter + return cn_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_cn should be the form of integer. The input now is in ", type(cn_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_cn should be the form of string. The input now is in ", type(cn_text)," type. Please retry and enter a string") + +# This function uses the following encoding: utf-8 +# Return a list of strings with English and Chinese words seperatly +def stats_text(string,count): + # Seperate the Chinese and English words into two strings by checking ASCII value + try: + en_text = "".join(i for i in string if ord(i) < 256).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + cn_text = "".join(j for j in string if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + return [stats_text_en(en_text,count),stats_text_cn(cn_text,count)] + except TypeError: + print("Error! The first input of function stats_text should be the form of string. The input now is in ", type(string)," type. Please retry and enter a string") From dd0f3d02f20c61efd1376d6e92f1d0b27e113ea3 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Thu, 29 Aug 2019 15:11:56 +0800 Subject: [PATCH 09/17] d11 day11 --- exercises/1901100240/d11/mymodule/main.py | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/exercises/1901100240/d11/mymodule/main.py b/exercises/1901100240/d11/mymodule/main.py index bedafc7f9..36cb7d506 100644 --- a/exercises/1901100240/d11/mymodule/main.py +++ b/exercises/1901100240/d11/mymodule/main.py @@ -1,25 +1,28 @@ +# Import the 微信文章 from the webside import requests -from pyquery import PyQuery -import stats_word -import getpass -import yagmail - response=requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') + +# Transer the 微信文章 to string type +from pyquery import PyQuery document = PyQuery(response.text) content = document('#js_content').text() + +# Make the satistic of the frequency of the word and output as a string +import stats_word stats = stats_word.stats_text_cn(content,100) -string=str('') +string=str('') # Create a string to store the result for unit in stats: + # Control the spacing by adding two more space it the word is less than two if len(unit[0]) <= 2: string += "'" + unit[0] + "'的频率是: " + str(unit[1]) + "\n" elif len(unit[0]) == 3: string += "'" + unit[0] + "'的频率是: " + str(unit[1]) + "\n" -sender = 'yanning931231@sina.com' -password = '7c50817e1ffff142' -recipients = '604332298@qq.com' -print(type(sender)) -yag = yagmail.SMTP(sender,password) -print(type(password)) -yag.send(to=recipients,subject='[你好]',contents=string) -print('done') \ No newline at end of file +# Send the result to the email +import yagmail +import getpass +sender = input('输⼊入发件⼈人邮箱:') +password = getpass.getpass('输⼊入发件⼈人邮箱密码(可复制粘贴):') # The password typed will be invisible but will still work +recipients = input('输⼊入收件⼈人邮箱:') +yag=yagmail.SMTP(sender,password,host='smtp.sina.com') +yag.send(to=recipients,subject='自学训练营学习19群+Ningziyun',contents=string) \ No newline at end of file From 3a2a4dceac6e12a5dc696eb2d7bf2b36422c27d7 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Thu, 29 Aug 2019 18:36:25 +0800 Subject: [PATCH 10/17] day 12 day 12 --- exercises/1901100240/d12/mymodule/main.py | 26 ++++++++++ .../1901100240/d12/mymodule/stats_word.py | 48 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 exercises/1901100240/d12/mymodule/main.py create mode 100644 exercises/1901100240/d12/mymodule/stats_word.py diff --git a/exercises/1901100240/d12/mymodule/main.py b/exercises/1901100240/d12/mymodule/main.py new file mode 100644 index 000000000..a9dbf660e --- /dev/null +++ b/exercises/1901100240/d12/mymodule/main.py @@ -0,0 +1,26 @@ +# Using wxpy to do the automatic reaply for sharing type +from wxpy import * +bot = Bot() + +# Doing the statistic for SHARING type +@bot.register(Chats,SHARING) +def print_statis(msg): + # Import the 微信文章 from the chat + import requests + response=requests.get(msg.url) + # Transer the 微信文章 to string type + from pyquery import PyQuery + document = PyQuery(response.text) + content = document('#js_content').text() + # Make the satistic of the frequency of the word and output as a string + import stats_word + stats = stats_word.stats_text_cn(content,100) + string=str('') # Create a string to store the result + for unit in stats: + # Control the spacing by adding two more space it the word is less than two + if len(unit[0]) <= 2: + string += "'" + unit[0] + "'的频率是: " + str(unit[1]) + "\n" + elif len(unit[0]) == 3: + string += "'" + unit[0] + "'的频率是: " + str(unit[1]) + "\n" + msg.reply(string) +embed() \ No newline at end of file diff --git a/exercises/1901100240/d12/mymodule/stats_word.py b/exercises/1901100240/d12/mymodule/stats_word.py new file mode 100644 index 000000000..dd30d6657 --- /dev/null +++ b/exercises/1901100240/d12/mymodule/stats_word.py @@ -0,0 +1,48 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +from collections import Counter +import jieba + +# Define the function +def stats_text_en(en_text,count): + try: + en_text = "".join(i for i in en_text if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + # Count the word use Counter + try: + en_count = Counter(en_text).most_common(count) # Create an counter + return en_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_en should be the form of integer. The input now is in ", type(en_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_en should be the form of string. The input now is in ", type(en_text)," type. Please retry and enter a string") + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every Chinese word using algrothm jieba +def stats_text_cn(cn_text,count): + try: + cn_text = "".join(j for j in cn_text if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + # Seprate the words in cn_text + cn_list=jieba.cut(cn_text,cut_all=False) + # Selected the words which length greater than two + cn_two_list=[] + for unit in cn_list: + if len(unit) >= 2: + cn_two_list.append(unit) + try: + cn_count = Counter(cn_two_list).most_common(count) # Create an counter + return cn_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_cn should be the form of integer. The input now is in ", type(cn_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_cn should be the form of string. The input now is in ", type(cn_text)," type. Please retry and enter a string") + +# This function uses the following encoding: utf-8 +# Return a list of strings with English and Chinese words seperatly +def stats_text(string,count): + # Seperate the Chinese and English words into two strings by checking ASCII value + try: + en_text = "".join(i for i in string if ord(i) < 256).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + cn_text = "".join(j for j in string if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + return [stats_text_en(en_text,count),stats_text_cn(cn_text,count)] + except TypeError: + print("Error! The first input of function stats_text should be the form of string. The input now is in ", type(string)," type. Please retry and enter a string") From a67a8fce90a15c17e33a89b90a768b91288416cb Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Fri, 30 Aug 2019 00:30:37 +0800 Subject: [PATCH 11/17] day12 day12 --- exercises/1901100240/d12/mymodule/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/1901100240/d12/mymodule/main.py b/exercises/1901100240/d12/mymodule/main.py index a9dbf660e..88c0d34cc 100644 --- a/exercises/1901100240/d12/mymodule/main.py +++ b/exercises/1901100240/d12/mymodule/main.py @@ -1,7 +1,7 @@ # Using wxpy to do the automatic reaply for sharing type from wxpy import * bot = Bot() - +Chats=bot.friends() # Doing the statistic for SHARING type @bot.register(Chats,SHARING) def print_statis(msg): From 3907897182ea60ca4b42f081a1def9ca6c32a648 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Fri, 30 Aug 2019 11:41:26 +0800 Subject: [PATCH 12/17] day13 day13 --- exercises/1901100240/d13/mymodule/main.py | 36 ++++++++++++++ .../1901100240/d13/mymodule/stats_word.py | 48 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 exercises/1901100240/d13/mymodule/main.py create mode 100644 exercises/1901100240/d13/mymodule/stats_word.py diff --git a/exercises/1901100240/d13/mymodule/main.py b/exercises/1901100240/d13/mymodule/main.py new file mode 100644 index 000000000..f53606602 --- /dev/null +++ b/exercises/1901100240/d13/mymodule/main.py @@ -0,0 +1,36 @@ +# Using wxpy to do the automatic reaply for sharing type +from wxpy import * +bot = Bot() +Chats=bot.friends() +# Doing the statistic for SHARING type +@bot.register(Chats,SHARING) +def print_statis(msg): + # Import the 微信文章 from the chat + import requests + response=requests.get(msg.url) + # Transer the 微信文章 to string type + from pyquery import PyQuery + document = PyQuery(response.text) + content = document('#js_content').text() + # Make the satistic of the frequency of the word and output as a string + import stats_word + stats = stats_word.stats_text_cn(content,10) + # Value is used to store frequency, index is used to store words + value = [] + index = [] + for unit in stats: + # Control the spacing by adding two more space it the word is less than two + value.append(unit[1]) + index.append(unit[0]) + # Create the plot + import matplotlib.pyplot as plt + scale = range(10) + plt.rcParams['font.family'] = ['sans-serif'] + plt.rcParams['font.sans-serif'] = ['SimHei'] + plt.title("微信公众号文章词频统计") + plt.xlabel("词汇") + plt.ylabel("词频") + plt.bar(scale,value) + plt.xticks(scale,index) + msg.reply(plt.show()) +embed() \ No newline at end of file diff --git a/exercises/1901100240/d13/mymodule/stats_word.py b/exercises/1901100240/d13/mymodule/stats_word.py new file mode 100644 index 000000000..dd30d6657 --- /dev/null +++ b/exercises/1901100240/d13/mymodule/stats_word.py @@ -0,0 +1,48 @@ +# This algorithm return the statistic result of the text +# It provide the frequency of every single words +from collections import Counter +import jieba + +# Define the function +def stats_text_en(en_text,count): + try: + en_text = "".join(i for i in en_text if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + # Count the word use Counter + try: + en_count = Counter(en_text).most_common(count) # Create an counter + return en_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_en should be the form of integer. The input now is in ", type(en_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_en should be the form of string. The input now is in ", type(en_text)," type. Please retry and enter a string") + +# This algorithm return the statistic result of the text in Chinese +# It provide the frequency of every Chinese word using algrothm jieba +def stats_text_cn(cn_text,count): + try: + cn_text = "".join(j for j in cn_text if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + # Seprate the words in cn_text + cn_list=jieba.cut(cn_text,cut_all=False) + # Selected the words which length greater than two + cn_two_list=[] + for unit in cn_list: + if len(unit) >= 2: + cn_two_list.append(unit) + try: + cn_count = Counter(cn_two_list).most_common(count) # Create an counter + return cn_count # Return the counter as result + except TypeError: + print("Error! The second input of function stats_text_cn should be the form of integer. The input now is in ", type(cn_text)," type. Please retry and enter a integer") + except TypeError: + print("Error! The first input of function stats_text_cn should be the form of string. The input now is in ", type(cn_text)," type. Please retry and enter a string") + +# This function uses the following encoding: utf-8 +# Return a list of strings with English and Chinese words seperatly +def stats_text(string,count): + # Seperate the Chinese and English words into two strings by checking ASCII value + try: + en_text = "".join(i for i in string if ord(i) < 256).replace("\n", " ") # ord() returns ASCII or Unicode value, less than 256 will provide the English words + cn_text = "".join(j for j in string if ord(j) > 256) # ord() returns ASCII or Unicode value, greater than 256 will provide the Chinese Character + return [stats_text_en(en_text,count),stats_text_cn(cn_text,count)] + except TypeError: + print("Error! The first input of function stats_text should be the form of string. The input now is in ", type(string)," type. Please retry and enter a string") From 707852b405fbf264269568acfbfac3228072a34f Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Fri, 30 Aug 2019 12:36:24 +0800 Subject: [PATCH 13/17] day 13 day 13 --- exercises/1901100240/d13/mymodule/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/1901100240/d13/mymodule/main.py b/exercises/1901100240/d13/mymodule/main.py index f53606602..49cb9ddeb 100644 --- a/exercises/1901100240/d13/mymodule/main.py +++ b/exercises/1901100240/d13/mymodule/main.py @@ -32,5 +32,6 @@ def print_statis(msg): plt.ylabel("词频") plt.bar(scale,value) plt.xticks(scale,index) - msg.reply(plt.show()) + plt.savefig("stats.png") # Save the image + msg.reply_image("stats.png") # Send the image as a result embed() \ No newline at end of file From a3b916ac0780cdd424fe818a32dac6976a6b25ab Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Fri, 30 Aug 2019 13:57:05 +0800 Subject: [PATCH 14/17] summary summary --- exercises/1901100240/README.md | 93 +++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/exercises/1901100240/README.md b/exercises/1901100240/README.md index 4b5b36487..5408e4402 100644 --- a/exercises/1901100240/README.md +++ b/exercises/1901100240/README.md @@ -1,2 +1,91 @@ -# hello-world -The project that usually used as the first repository +### 课程总结 + +# Github +除编译器之外的重要协作软件Github,其功能类似于编程版本的Google Doc,可以允许多人同时编程。 +对每段更改保有历史记录,可回溯任意更改,避免代码被覆盖,且可回溯任意版本 +Github建立在分支架构之上,主分支负责程序主体,dev分支则可供个人修改使用。个人修改的程序可通过pull request请求并入主分支。此功能保证多人同时协作的同时,亦可以避免程序被个人错误更改 +通过folk加入其他repository,通过clone下载到本地,通过commit讲更改提交到主分支,通过pull request将修改提交 + +# Python 编译器 +Anaconda-Navigator 综合了数个python编译器 +Visual Studio Code适合快速编译python shell内容,界面视觉效果较好。Spyder适合做短代码测试,界面一般 +Visual Studio Cose 和 Spyder 保存的代码可以自动同步,方便转换 +在python shell中需要print将数值显示,否则默认隐藏 + +# Hello Word +约定俗称的语言入门所编写的第一个程序 +Print作为python输出,在python shell内不print的内容默认隐藏 +print时以'/t'控制同行空格打印 +print时以''换新的一行 + +# 结构类型 +有字典(dictionary),元组(tuple),列表(list)等储存单位 +元组和列表是以位置储存元素,位置0对应第一元素,位置1对应第二元素,构成元素和位置一一对应的关系 +字典是以key和item进行一一对应 +元组内部数据无法更改 +字典用于统计数字较为方便 + +# 循环 +for loop 和 while loop是最常用的两种循环模式 +for loop不仅可以进行数字循环,也可以进行列表中元素的循环 +while loop可以通过 while True 不断循环直到达成条件break +break会跳出最内层的循环 +当过多循环减慢速度时,可采用numpy替代 + +# try...except +阻止程序进入error,可保证代码继续运行 +可暂时忽略无效代码 +配合try...except然后print,可进行debuging + +# Debug +bug可以双轴分为四象限:横轴为显性,隐性;纵轴为持续性,间歇性 +隐性bug比显性bug危险,间歇性bug比持续性危险 +显性bug程序会直接报错,易于发现;隐性bug程序不会报错,但输出结果与预期不符,更难发现 +持续性bug每次运行都会出现,间歇性只会在特殊情况下出现 +千年虫既为典型隐性间歇性bug +Debug过程,需要讲代码分为不同模块,检测不同模块结果,发现模块结果错误既修改之 +修改单一模块后,仍需整体运行以保证输出正确 + +# 排序 +计算机编程的重要组成部分 +不同的排序方式会产生巨大的速度差别 + +# 模块 +将已经编写好的代码作为模块保存,可以在其他程序中进行调用 +调用所需时间较长 +可使得程序简洁明了 + +# 画图 +画图逻辑与matlab相似 +需要导入matplotlib包函数 +处理速度相对较慢 +matplotlib包本身不支持中文,故需要通过一下代码导入中文: + lt.rcParams['font.family'] = ['sans-serif'] + plt.rcParams['font.sans-serif'] = ['SimHei'] + +# yagmail +可进行收发邮件,配合try..except使用,可保证在程序出错时迅速收到提醒 +邮件发送前邮箱需要授权Pop/SMTP +授权后以授权码代替密码 +getpass默认隐藏密码,输入不可见 +yagmail.SMTP()中host需要输入,否则出现超时错误 + +# getpass +可用于获取密码,其特点为密码会呈现不可见状态,以保护密码安全 + +# wxpy +微信外链程序,可编写自动回复脚本 +基于webweixin进行,有可能被微信web封号 + +# jieba +中文分词包,其共嫩建立在内含的词典之上 +可通过jieba进行词频统计 +jieba输出为不可见的list形式 + +### 自学相关 +凡是知道方向,大部分问题都可通过搜索引擎解决 +寻找方向是自学的关键 +自定一个Project,以解决问题的形式进行学习,倒逼学习相关知识 +自学可能产生回音室效应,产生自循环,也就是倾向于用已知知识解决新问题,因此需要时时与他人对比 +部分问题已经有人做出更好解答,不可迷恋自身能力 +相对于系统化学习,可能漏过部分基础,使得无知于某些高效解决方案 \ No newline at end of file From b128cc07fa32d2431eadcc97bf4cd0538d779f43 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Fri, 30 Aug 2019 14:02:27 +0800 Subject: [PATCH 15/17] summary summary --- exercises/1901100240/README.md | 68 ++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/exercises/1901100240/README.md b/exercises/1901100240/README.md index 5408e4402..542e2835d 100644 --- a/exercises/1901100240/README.md +++ b/exercises/1901100240/README.md @@ -1,43 +1,56 @@ -### 课程总结 +# 课程总结 -# Github -除编译器之外的重要协作软件Github,其功能类似于编程版本的Google Doc,可以允许多人同时编程。 +### Github +''' +除编译器之外的重要协作软件Github,其功能类似于编程版本的Google Doc,可以允许多人同时编程 对每段更改保有历史记录,可回溯任意更改,避免代码被覆盖,且可回溯任意版本 Github建立在分支架构之上,主分支负责程序主体,dev分支则可供个人修改使用。个人修改的程序可通过pull request请求并入主分支。此功能保证多人同时协作的同时,亦可以避免程序被个人错误更改 通过folk加入其他repository,通过clone下载到本地,通过commit讲更改提交到主分支,通过pull request将修改提交 +''' -# Python 编译器 -Anaconda-Navigator 综合了数个python编译器 +### Python 编译器 +''' +Anaconda-Navigator 综合了数个python编译器。 Visual Studio Code适合快速编译python shell内容,界面视觉效果较好。Spyder适合做短代码测试,界面一般 Visual Studio Cose 和 Spyder 保存的代码可以自动同步,方便转换 在python shell中需要print将数值显示,否则默认隐藏 +''' -# Hello Word +### Hello Word +''' 约定俗称的语言入门所编写的第一个程序 Print作为python输出,在python shell内不print的内容默认隐藏 print时以'/t'控制同行空格打印 print时以''换新的一行 +''' -# 结构类型 +### 结构类型 +''' 有字典(dictionary),元组(tuple),列表(list)等储存单位 元组和列表是以位置储存元素,位置0对应第一元素,位置1对应第二元素,构成元素和位置一一对应的关系 字典是以key和item进行一一对应 元组内部数据无法更改 字典用于统计数字较为方便 +''' -# 循环 +### 循环 +''' for loop 和 while loop是最常用的两种循环模式 for loop不仅可以进行数字循环,也可以进行列表中元素的循环 while loop可以通过 while True 不断循环直到达成条件break break会跳出最内层的循环 当过多循环减慢速度时,可采用numpy替代 +''' -# try...except +### try...except +''' 阻止程序进入error,可保证代码继续运行 可暂时忽略无效代码 配合try...except然后print,可进行debuging +''' -# Debug +### Debug +''' bug可以双轴分为四象限:横轴为显性,隐性;纵轴为持续性,间歇性 隐性bug比显性bug危险,间歇性bug比持续性危险 显性bug程序会直接报错,易于发现;隐性bug程序不会报错,但输出结果与预期不符,更难发现 @@ -45,47 +58,64 @@ bug可以双轴分为四象限:横轴为显性,隐性;纵轴为持续性 千年虫既为典型隐性间歇性bug Debug过程,需要讲代码分为不同模块,检测不同模块结果,发现模块结果错误既修改之 修改单一模块后,仍需整体运行以保证输出正确 +''' -# 排序 +### 排序 +''' 计算机编程的重要组成部分 不同的排序方式会产生巨大的速度差别 +''' -# 模块 +### 模块 +''' 将已经编写好的代码作为模块保存,可以在其他程序中进行调用 调用所需时间较长 可使得程序简洁明了 +''' -# 画图 +### 画图 +''' 画图逻辑与matlab相似 需要导入matplotlib包函数 处理速度相对较慢 matplotlib包本身不支持中文,故需要通过一下代码导入中文: lt.rcParams['font.family'] = ['sans-serif'] plt.rcParams['font.sans-serif'] = ['SimHei'] +''' -# yagmail +### yagmail +''' 可进行收发邮件,配合try..except使用,可保证在程序出错时迅速收到提醒 邮件发送前邮箱需要授权Pop/SMTP 授权后以授权码代替密码 getpass默认隐藏密码,输入不可见 yagmail.SMTP()中host需要输入,否则出现超时错误 +''' -# getpass +### getpass +''' 可用于获取密码,其特点为密码会呈现不可见状态,以保护密码安全 +''' -# wxpy +### wxpy +''' 微信外链程序,可编写自动回复脚本 基于webweixin进行,有可能被微信web封号 +''' -# jieba +### jieba +''' 中文分词包,其共嫩建立在内含的词典之上 可通过jieba进行词频统计 jieba输出为不可见的list形式 +''' -### 自学相关 +# 自学相关 +''' 凡是知道方向,大部分问题都可通过搜索引擎解决 寻找方向是自学的关键 自定一个Project,以解决问题的形式进行学习,倒逼学习相关知识 自学可能产生回音室效应,产生自循环,也就是倾向于用已知知识解决新问题,因此需要时时与他人对比 部分问题已经有人做出更好解答,不可迷恋自身能力 -相对于系统化学习,可能漏过部分基础,使得无知于某些高效解决方案 \ No newline at end of file +相对于系统化学习,可能漏过部分基础,使得无知于某些高效解决方案 +''' \ No newline at end of file From b7a429ee1ef8681577ebbb04c15952b58f5ce59f Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Fri, 30 Aug 2019 14:03:52 +0800 Subject: [PATCH 16/17] summary summary --- exercises/1901100240/README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/exercises/1901100240/README.md b/exercises/1901100240/README.md index 542e2835d..45818bc26 100644 --- a/exercises/1901100240/README.md +++ b/exercises/1901100240/README.md @@ -1,14 +1,12 @@ # 课程总结 -### Github -''' -除编译器之外的重要协作软件Github,其功能类似于编程版本的Google Doc,可以允许多人同时编程 +# Github +除编译器之外的重要协作软件Github,其功能类似于编程版本的Google Doc,可以允许多人同时编程\n 对每段更改保有历史记录,可回溯任意更改,避免代码被覆盖,且可回溯任意版本 Github建立在分支架构之上,主分支负责程序主体,dev分支则可供个人修改使用。个人修改的程序可通过pull request请求并入主分支。此功能保证多人同时协作的同时,亦可以避免程序被个人错误更改 通过folk加入其他repository,通过clone下载到本地,通过commit讲更改提交到主分支,通过pull request将修改提交 -''' -### Python 编译器 +# Python 编译器 ''' Anaconda-Navigator 综合了数个python编译器。 Visual Studio Code适合快速编译python shell内容,界面视觉效果较好。Spyder适合做短代码测试,界面一般 @@ -16,7 +14,7 @@ Visual Studio Cose 和 Spyder 保存的代码可以自动同步,方便转换 在python shell中需要print将数值显示,否则默认隐藏 ''' -### Hello Word +# Hello Word ''' 约定俗称的语言入门所编写的第一个程序 Print作为python输出,在python shell内不print的内容默认隐藏 @@ -24,7 +22,7 @@ print时以'/t'控制同行空格打印 print时以''换新的一行 ''' -### 结构类型 +# 结构类型 ''' 有字典(dictionary),元组(tuple),列表(list)等储存单位 元组和列表是以位置储存元素,位置0对应第一元素,位置1对应第二元素,构成元素和位置一一对应的关系 From 0408a2c0bd0a5faf13766db15e7d17aab7452a95 Mon Sep 17 00:00:00 2001 From: Ningziyun <49535971+Ningziyun@users.noreply.github.com> Date: Fri, 30 Aug 2019 14:07:27 +0800 Subject: [PATCH 17/17] summary summary --- exercises/1901100240/README.md | 160 ++++++++++++++------------------- 1 file changed, 66 insertions(+), 94 deletions(-) diff --git a/exercises/1901100240/README.md b/exercises/1901100240/README.md index 45818bc26..ed1012a03 100644 --- a/exercises/1901100240/README.md +++ b/exercises/1901100240/README.md @@ -1,119 +1,91 @@ # 课程总结 # Github -除编译器之外的重要协作软件Github,其功能类似于编程版本的Google Doc,可以允许多人同时编程\n -对每段更改保有历史记录,可回溯任意更改,避免代码被覆盖,且可回溯任意版本 -Github建立在分支架构之上,主分支负责程序主体,dev分支则可供个人修改使用。个人修改的程序可通过pull request请求并入主分支。此功能保证多人同时协作的同时,亦可以避免程序被个人错误更改 -通过folk加入其他repository,通过clone下载到本地,通过commit讲更改提交到主分支,通过pull request将修改提交 +除编译器之外的重要协作软件Github,其功能类似于编程版本的Google Doc,可以允许多人同时编程。 +对每段更改保有历史记录,可回溯任意更改,避免代码被覆盖,且可回溯任意版本。 +Github建立在分支架构之上,主分支负责程序主体,dev分支则可供个人修改使用。个人修改的程序可通过pull request请求并入主分支。此功能保证多人同时协作的同时,亦可以避免程序被个人错误更改。 +通过folk加入其他repository,通过clone下载到本地,通过commit讲更改提交到主分支,通过pull request将修改提交。 # Python 编译器 -''' Anaconda-Navigator 综合了数个python编译器。 -Visual Studio Code适合快速编译python shell内容,界面视觉效果较好。Spyder适合做短代码测试,界面一般 -Visual Studio Cose 和 Spyder 保存的代码可以自动同步,方便转换 -在python shell中需要print将数值显示,否则默认隐藏 -''' +Visual Studio Code适合快速编译python shell内容,界面视觉效果较好。Spyder适合做短代码测试,界面一般。 +Visual Studio Cose 和 Spyder 保存的代码可以自动同步,方便转换。 +在python shell中需要print将数值显示,否则默认隐藏。 # Hello Word -''' -约定俗称的语言入门所编写的第一个程序 -Print作为python输出,在python shell内不print的内容默认隐藏 -print时以'/t'控制同行空格打印 -print时以''换新的一行 -''' +约定俗称的语言入门所编写的第一个程序。 +Print作为python输出,在python shell内不print的内容默认隐藏。 +print时以'/t'控制同行空格打印。 +print时以''换新的一行。 # 结构类型 -''' -有字典(dictionary),元组(tuple),列表(list)等储存单位 -元组和列表是以位置储存元素,位置0对应第一元素,位置1对应第二元素,构成元素和位置一一对应的关系 -字典是以key和item进行一一对应 -元组内部数据无法更改 -字典用于统计数字较为方便 -''' +有字典(dictionary),元组(tuple),列表(list)等储存单位。 +元组和列表是以位置储存元素,位置0对应第一元素,位置1对应第二元素,构成元素和位置一一对应的关系。 +字典是以key和item进行一一对应。 +元组内部数据无法更改。 +字典用于统计数字较为方便。 -### 循环 -''' -for loop 和 while loop是最常用的两种循环模式 -for loop不仅可以进行数字循环,也可以进行列表中元素的循环 -while loop可以通过 while True 不断循环直到达成条件break -break会跳出最内层的循环 -当过多循环减慢速度时,可采用numpy替代 -''' +# 循环 +for loop 和 while loop是最常用的两种循环模式。 +for loop不仅可以进行数字循环,也可以进行列表中元素的循环。 +while loop可以通过 while True 不断循环直到达成条件break。 +break会跳出最内层的循环。 +当过多循环减慢速度时,可采用numpy替代。 -### try...except -''' -阻止程序进入error,可保证代码继续运行 -可暂时忽略无效代码 -配合try...except然后print,可进行debuging -''' +# try...except +阻止程序进入error,可保证代码继续运行。 +可暂时忽略无效代码。 +配合try...except然后print,可进行debuging。 -### Debug -''' -bug可以双轴分为四象限:横轴为显性,隐性;纵轴为持续性,间歇性 -隐性bug比显性bug危险,间歇性bug比持续性危险 -显性bug程序会直接报错,易于发现;隐性bug程序不会报错,但输出结果与预期不符,更难发现 -持续性bug每次运行都会出现,间歇性只会在特殊情况下出现 -千年虫既为典型隐性间歇性bug -Debug过程,需要讲代码分为不同模块,检测不同模块结果,发现模块结果错误既修改之 -修改单一模块后,仍需整体运行以保证输出正确 -''' +# Debug +bug可以双轴分为四象限:横轴为显性,隐性;纵轴为持续性,间歇性。 +隐性bug比显性bug危险,间歇性bug比持续性危险。 +显性bug程序会直接报错,易于发现;隐性bug程序不会报错,但输出结果与预期不符,更难发现。 +持续性bug每次运行都会出现,间歇性只会在特殊情况下出现。 +千年虫既为典型隐性间歇性bug。 +Debug过程,需要讲代码分为不同模块,检测不同模块结果,发现模块结果错误既修改之。 +修改单一模块后,仍需整体运行以保证输出正确。 -### 排序 -''' -计算机编程的重要组成部分 -不同的排序方式会产生巨大的速度差别 -''' +# 排序 +计算机编程的重要组成部分。 +不同的排序方式会产生巨大的速度差别。 -### 模块 -''' -将已经编写好的代码作为模块保存,可以在其他程序中进行调用 -调用所需时间较长 -可使得程序简洁明了 -''' +# 模块 +将已经编写好的代码作为模块保存,可以在其他程序中进行调用。 +调用所需时间较长。 +可使得程序简洁明了。 -### 画图 -''' -画图逻辑与matlab相似 -需要导入matplotlib包函数 -处理速度相对较慢 +# 画图 +画图逻辑与matlab相似。 +需要导入matplotlib包函数。 +处理速度相对较慢。 matplotlib包本身不支持中文,故需要通过一下代码导入中文: lt.rcParams['font.family'] = ['sans-serif'] plt.rcParams['font.sans-serif'] = ['SimHei'] -''' -### yagmail -''' -可进行收发邮件,配合try..except使用,可保证在程序出错时迅速收到提醒 -邮件发送前邮箱需要授权Pop/SMTP -授权后以授权码代替密码 -getpass默认隐藏密码,输入不可见 -yagmail.SMTP()中host需要输入,否则出现超时错误 -''' +# yagmail +可进行收发邮件,配合try..except使用,可保证在程序出错时迅速收到提醒。 +邮件发送前邮箱需要授权Pop/SMTP。 +授权后以授权码代替密码。 +getpass默认隐藏密码,输入不可见。 +yagmail.SMTP()中host需要输入,否则出现超时错误。 -### getpass -''' -可用于获取密码,其特点为密码会呈现不可见状态,以保护密码安全 -''' +# getpass +可用于获取密码,其特点为密码会呈现不可见状态,以保护密码安全。 -### wxpy -''' -微信外链程序,可编写自动回复脚本 -基于webweixin进行,有可能被微信web封号 -''' +# wxpy +微信外链程序,可编写自动回复脚本。 +基于webweixin进行,有可能被微信web封号。 -### jieba -''' -中文分词包,其共嫩建立在内含的词典之上 -可通过jieba进行词频统计 -jieba输出为不可见的list形式 -''' +# jieba +中文分词包,其共嫩建立在内含的词典之上。 +可通过jieba进行词频统计。 +jieba输出为不可见的list形式。 # 自学相关 -''' -凡是知道方向,大部分问题都可通过搜索引擎解决 -寻找方向是自学的关键 -自定一个Project,以解决问题的形式进行学习,倒逼学习相关知识 -自学可能产生回音室效应,产生自循环,也就是倾向于用已知知识解决新问题,因此需要时时与他人对比 -部分问题已经有人做出更好解答,不可迷恋自身能力 -相对于系统化学习,可能漏过部分基础,使得无知于某些高效解决方案 -''' \ No newline at end of file +凡是知道方向,大部分问题都可通过搜索引擎解决。 +寻找方向是自学的关键。 +自定一个Project,以解决问题的形式进行学习,倒逼学习相关知识。 +自学可能产生回音室效应,产生自循环,也就是倾向于用已知知识解决新问题,因此需要时时与他人对比。 +部分问题已经有人做出更好解答,不可迷恋自身能力。 +相对于系统化学习,可能漏过部分基础,使得无知于某些高效解决方案。 \ No newline at end of file