From dc4b551c5485ddd33783bb609044879f63d8b7b5 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Sat, 10 Aug 2019 23:21:59 +0800 Subject: [PATCH 01/11] Create 1001S02E03_ca1cu1ator.py --- exercises/1901100053/1001S02E03_ca1cu1ator.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 exercises/1901100053/1001S02E03_ca1cu1ator.py diff --git a/exercises/1901100053/1001S02E03_ca1cu1ator.py b/exercises/1901100053/1001S02E03_ca1cu1ator.py new file mode 100644 index 000000000..e69de29bb From fab0a887ead9b316835d16253c81af560ea700f5 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Sun, 11 Aug 2019 15:03:13 +0800 Subject: [PATCH 02/11] Update 1001S02E03_ca1cu1ator.py --- exercises/1901100053/1001S02E03_ca1cu1ator.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/exercises/1901100053/1001S02E03_ca1cu1ator.py b/exercises/1901100053/1001S02E03_ca1cu1ator.py index e69de29bb..69eece636 100644 --- a/exercises/1901100053/1001S02E03_ca1cu1ator.py +++ b/exercises/1901100053/1001S02E03_ca1cu1ator.py @@ -0,0 +1,21 @@ +operator = input('请输入运算符(+、-、*、/):') +first_number = input('请输入第一位数字:') +second_number = input('请输入第二位数字:') +a = int(first_number) +b = int(second_number) +print('operator:', operator, type(operator)) +print('first_number:',first_number, type(first_number),type(a)) +print('second_number:',second_number,type(second_number),type(b)) +print('测试加法 str 加法:', first_number + second_number) +# print('测试加法 str 减法:', first_number - second_number) +if operator == '+': + print(a, '+',b,'=',a+b) +elif operator == '-': + print(a,'-',b,'=',a-b) +elif operator == '*': + print(a,'*',b,'=',a*b) +elif operator == '/': + print(a,'/',b,'=',a/b) +else: + print('无效的运算符') + # raise valueError('无效的运算符') From 42debf5f2d9c3300814959a492c0d2061019f02f Mon Sep 17 00:00:00 2001 From: boy-35 Date: Sun, 11 Aug 2019 17:19:11 +0800 Subject: [PATCH 03/11] =?UTF-8?q?1901100053=20day4=20=E4=BA=8E=E9=87=91?= =?UTF-8?q?=E6=A1=A5=2014=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1901100053/1001S02E04_control_flow.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 exercises/1901100053/1001S02E04_control_flow.py diff --git a/exercises/1901100053/1001S02E04_control_flow.py b/exercises/1901100053/1001S02E04_control_flow.py new file mode 100644 index 000000000..2ddd83901 --- /dev/null +++ b/exercises/1901100053/1001S02E04_control_flow.py @@ -0,0 +1,19 @@ + +print('打印九九乘法表') +for i in range(1,10): + print('第%d行' %i,end='\t') + for j in range(1, i+1): + # print(i,'*',j,'=',i*j,end='\t') + print('{}*{}={}'.format(i,j,i*j),end='\t') + print() + + # print('\n打印跳过偶数行的九九乘法表') +i = 1 +while i<10: + if i % 2 == 0: + print() + else: + for j in range(1,i+1): + print(i,'*',j,'=',i*j,end='\t') + # print('{}*{}={}'.format(i,j,i*j),end='\t') + i += 1 \ No newline at end of file From 7083156e7eb72801a433bf51abe067ad7f43a968 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Thu, 15 Aug 2019 00:09:51 +0800 Subject: [PATCH 04/11] Create day5_string.py.txt --- exercises/1901100053/day5_string.py.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 exercises/1901100053/day5_string.py.txt diff --git a/exercises/1901100053/day5_string.py.txt b/exercises/1901100053/day5_string.py.txt new file mode 100644 index 000000000..e69de29bb From d95d8cbf2861f3496d4708babdcfde3b22766204 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Thu, 15 Aug 2019 20:27:18 +0800 Subject: [PATCH 05/11] day5_string.py --- exercises/1901100053/{day5_string.py.txt => day5_string.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/1901100053/{day5_string.py.txt => day5_string.py} (100%) diff --git a/exercises/1901100053/day5_string.py.txt b/exercises/1901100053/day5_string.py similarity index 100% rename from exercises/1901100053/day5_string.py.txt rename to exercises/1901100053/day5_string.py From 1d1d417270b7dde1aa2b0a525b774ff77b50ce9b Mon Sep 17 00:00:00 2001 From: boy-35 Date: Fri, 16 Aug 2019 23:34:06 +0800 Subject: [PATCH 06/11] Create day5_stats_text.py --- exercises/1901100053/day5_stats_text.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 exercises/1901100053/day5_stats_text.py diff --git a/exercises/1901100053/day5_stats_text.py b/exercises/1901100053/day5_stats_text.py new file mode 100644 index 000000000..e69de29bb From 919c9d4d9d1ede600dd682df90c95a3e6ecbc63f Mon Sep 17 00:00:00 2001 From: boy-35 Date: Sun, 18 Aug 2019 17:29:32 +0800 Subject: [PATCH 07/11] day5 1901100053 --- exercises/1901100053/day5_stats_text.py.py | 64 ++++++++++++++++++++++ exercises/1901100053/day5_string.py.py | 52 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 exercises/1901100053/day5_stats_text.py.py create mode 100644 exercises/1901100053/day5_string.py.py diff --git a/exercises/1901100053/day5_stats_text.py.py b/exercises/1901100053/day5_stats_text.py.py new file mode 100644 index 000000000..faedee55e --- /dev/null +++ b/exercises/1901100053/day5_stats_text.py.py @@ -0,0 +1,64 @@ +sample_text = ''' +The Zen Of Python ,by Tim peetrs + + +Beautiful is beter than ugly. +Explicit is better than complex. +Simple is better than complicated. +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 silenced. +Unless explcitly 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 bsd idea. +If the implementation si easy to explain,it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +# 1. 使用字典(dict 类型)统计字符串样本 text 中各个英文单词出现的次数 + +# 先进将字符串根据空白字符分割成 list , 要调用 str 类型 +elements = sample_text.split() + +# 定义一个新的 list 型变量,存储处理过的单词 +words = [] + +# 先针对样本挑选需要剔除的非单词符号 +symbols = ',.*-!' + +for element in elements: + # 遍历一遍要剔除的符号 + for symbol in symbols: + # 逐个替换字符号, 用 '' 是为了同时剔除符号所占的位置 + element= element.replace(symbol, '') + # 剔除了字符后 如果 element 的 长度不为 0 则算作正常单词 + if len(element): + words.append(element) + +print('正常的英文单词==>',words) + +# 初始化一个 dict (字典)类型的变量, 用来存放单词出现的次数 +counter = {} + +# set (集合) 类型 可以去掉 列表里的重复元素,可以在 for...in 里减少循环次数 +word_set = set(words) + +for word in word_set: + counter[word]=words.count[word] + +print('英文单词出现的次数==>', counter) + +# 2. 按照出现次数从大到小输出所有的单词及出现的次数 + +# 内置函数 sorted 的参数 key 表示按元素的那一项的值进行排序 +# dict 类型 counter 的 items 方法会返回一个包含相应项(key .value) 的元组 列表 +# print('counter.items()==>', counter.itemse()) +print('从大到小输出所有的单词及出现的次数==>', sorted(counter.items(), key = lambda x: x[1], reverse = true)) \ No newline at end of file diff --git a/exercises/1901100053/day5_string.py.py b/exercises/1901100053/day5_string.py.py new file mode 100644 index 000000000..a0b5d19bc --- /dev/null +++ b/exercises/1901100053/day5_string.py.py @@ -0,0 +1,52 @@ +sample_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 ! +''' + +# 1.将字符串样本里的 better 全部替换成 worse + +# 调用 str 类型 的 replace 方法进行替换 +text = sample_text.replace('better','worse') +print('将字符串样本里的 better 全部替换成 worse ==>',text) + +# 2. 将单词中包含 ea 的单词剔除 + +# 先将字符串根据空白字符分割成 list ,要调用 str 类型 +words = text_split() +# 定义一个 list 类型的变量用来存放过滤完的单词 +filterde = [] +# 用 for...in 循环遍历一遍 words 里的元素然后判断单词是否包含 ea +for word in words: + # str 类型的 find 方法 如果不包含 参数 字符则返回 -1 ,如果包含则返回该字符第一次出现时的索引 + if word.find('ea') < 0: + filterde.append(word) +print('将单词中包含 ea 的单词剔除==>', filterde) + +# 3. 进行大小写翻转 +# 利用列表推倒式 对 str 类型的元素进行大小写翻转 +swapcased = [i.swapcase() for i in filtered] +print('进行大小写翻转 == >', swapcased) + +# 4.单词按 a_z 升序排列 +# print('单词按 a_z 升序排列==>', sorted(swapcased)) +print('单词按 a_z 降序排列==>', sorted(swapcased, reverse=True)) \ No newline at end of file From 19f5e47e7b696cfb0aa813013dccc7dd8ea8f1f0 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Sun, 18 Aug 2019 18:21:08 +0800 Subject: [PATCH 08/11] day5 1901100053 --- exercises/1901100053/1001S02E02_hello_python.py | 2 +- exercises/1901100053/day5_array.py.txt | 14 ++++++++++++++ exercises/1901100053/day5_stats_text.py | 0 exercises/1901100053/day5_string.py | 0 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 exercises/1901100053/day5_array.py.txt delete mode 100644 exercises/1901100053/day5_stats_text.py delete mode 100644 exercises/1901100053/day5_string.py diff --git a/exercises/1901100053/1001S02E02_hello_python.py b/exercises/1901100053/1001S02E02_hello_python.py index afcffc0d6..cfa8d7507 100644 --- a/exercises/1901100053/1001S02E02_hello_python.py +++ b/exercises/1901100053/1001S02E02_hello_python.py @@ -1 +1 @@ -print("hello world" \ No newline at end of file +print("hello world"!) \ No newline at end of file diff --git a/exercises/1901100053/day5_array.py.txt b/exercises/1901100053/day5_array.py.txt new file mode 100644 index 000000000..3c8ed1c0b --- /dev/null +++ b/exercises/1901100053/day5_array.py.txt @@ -0,0 +1,14 @@ +sample_list=[0,1,2,3,,5,6.7,8,9,] +reversed_list=sample_list[::-1] +print('列表翻转==>', reversed_list) +joined_str = ''.join([str(i) for i in reversed_list]) +print('翻转后的数组拼接成字符串==>', joined_str) +sliced_str = joined_str[2:8] +print('用字符串切片的方式取出第三到第八个字符==>', sliced_str) +reversed_list = sliced_str[::-1] +print('字符串翻转==>', reversed_str) +int_value = int(reversed_str) +print('转换为 int 类型==>', int _value) +print('转换为 二进制==>', bin(int_value)) +print('转换为 八进制==>', oct(int_value)) +print('转换为 十六进制==>', hex(int_value)) \ No newline at end of file diff --git a/exercises/1901100053/day5_stats_text.py b/exercises/1901100053/day5_stats_text.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/exercises/1901100053/day5_string.py b/exercises/1901100053/day5_string.py deleted file mode 100644 index e69de29bb..000000000 From 87736907e94113b5b71c90898a0467e2ac597293 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Sun, 18 Aug 2019 23:25:13 +0800 Subject: [PATCH 09/11] day5 1901100053 --- .../{day5_array.py.txt => day5_array.py} | 15 +++++++++++---- .../{day5_stats_text.py.py => day5_stats_text.py} | 0 .../{day5_string.py.py => day5_string.py} | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) rename exercises/1901100053/{day5_array.py.txt => day5_array.py} (50%) rename exercises/1901100053/{day5_stats_text.py.py => day5_stats_text.py} (100%) rename exercises/1901100053/{day5_string.py.py => day5_string.py} (98%) diff --git a/exercises/1901100053/day5_array.py.txt b/exercises/1901100053/day5_array.py similarity index 50% rename from exercises/1901100053/day5_array.py.txt rename to exercises/1901100053/day5_array.py index 3c8ed1c0b..68b5fbc99 100644 --- a/exercises/1901100053/day5_array.py.txt +++ b/exercises/1901100053/day5_array.py @@ -1,14 +1,21 @@ -sample_list=[0,1,2,3,,5,6.7,8,9,] +# 列表也叫做数组 +# 1.对列表[0,1,2,3,4,5,6,7,8,9,]翻转 +sample_list=[0,1,2,3,4,5,6.7,8,9,] reversed_list=sample_list[::-1] print('列表翻转==>', reversed_list) +# 2.翻转后的列表拼接成字符串 +# 调用 '' 翻转后的列表拼接成字符串 joined_str = ''.join([str(i) for i in reversed_list]) print('翻转后的数组拼接成字符串==>', joined_str) +# 3. 用字符串切片的方式取出第三个第八个字符(包含第三和第八个字符) sliced_str = joined_str[2:8] print('用字符串切片的方式取出第三到第八个字符==>', sliced_str) -reversed_list = sliced_str[::-1] -print('字符串翻转==>', reversed_str) +# 4.获得的字符串进行翻转 +reversed_str = sliced_str[::-1] +print('字符串翻转==>',reversed_str) +# 5. 转换为 int 类型 int_value = int(reversed_str) -print('转换为 int 类型==>', int _value) +print('转换为 int 类型==>', int_value) print('转换为 二进制==>', bin(int_value)) print('转换为 八进制==>', oct(int_value)) print('转换为 十六进制==>', hex(int_value)) \ No newline at end of file diff --git a/exercises/1901100053/day5_stats_text.py.py b/exercises/1901100053/day5_stats_text.py similarity index 100% rename from exercises/1901100053/day5_stats_text.py.py rename to exercises/1901100053/day5_stats_text.py diff --git a/exercises/1901100053/day5_string.py.py b/exercises/1901100053/day5_string.py similarity index 98% rename from exercises/1901100053/day5_string.py.py rename to exercises/1901100053/day5_string.py index a0b5d19bc..57c9ec23f 100644 --- a/exercises/1901100053/day5_string.py.py +++ b/exercises/1901100053/day5_string.py @@ -32,7 +32,7 @@ # 2. 将单词中包含 ea 的单词剔除 # 先将字符串根据空白字符分割成 list ,要调用 str 类型 -words = text_split() +words = text.split() # 定义一个 list 类型的变量用来存放过滤完的单词 filterde = [] # 用 for...in 循环遍历一遍 words 里的元素然后判断单词是否包含 ea From 67c44357989faa9d2499d173811bd60c74d32f47 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Mon, 19 Aug 2019 00:03:35 +0800 Subject: [PATCH 10/11] day5 1901100053 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这个是对的 --- exercises/1901100053/day5_array.py.txt | 14 ++++++++++++++ exercises/1901100053/day5_string.py | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 exercises/1901100053/day5_array.py.txt diff --git a/exercises/1901100053/day5_array.py.txt b/exercises/1901100053/day5_array.py.txt new file mode 100644 index 000000000..3c8ed1c0b --- /dev/null +++ b/exercises/1901100053/day5_array.py.txt @@ -0,0 +1,14 @@ +sample_list=[0,1,2,3,,5,6.7,8,9,] +reversed_list=sample_list[::-1] +print('列表翻转==>', reversed_list) +joined_str = ''.join([str(i) for i in reversed_list]) +print('翻转后的数组拼接成字符串==>', joined_str) +sliced_str = joined_str[2:8] +print('用字符串切片的方式取出第三到第八个字符==>', sliced_str) +reversed_list = sliced_str[::-1] +print('字符串翻转==>', reversed_str) +int_value = int(reversed_str) +print('转换为 int 类型==>', int _value) +print('转换为 二进制==>', bin(int_value)) +print('转换为 八进制==>', oct(int_value)) +print('转换为 十六进制==>', hex(int_value)) \ No newline at end of file diff --git a/exercises/1901100053/day5_string.py b/exercises/1901100053/day5_string.py index 57c9ec23f..dafdd7430 100644 --- a/exercises/1901100053/day5_string.py +++ b/exercises/1901100053/day5_string.py @@ -34,18 +34,18 @@ # 先将字符串根据空白字符分割成 list ,要调用 str 类型 words = text.split() # 定义一个 list 类型的变量用来存放过滤完的单词 -filterde = [] +filtered = [] # 用 for...in 循环遍历一遍 words 里的元素然后判断单词是否包含 ea for word in words: # str 类型的 find 方法 如果不包含 参数 字符则返回 -1 ,如果包含则返回该字符第一次出现时的索引 if word.find('ea') < 0: - filterde.append(word) -print('将单词中包含 ea 的单词剔除==>', filterde) + filtered.append(word) +print('将单词中包含 ea 的单词剔除==>', filtered) # 3. 进行大小写翻转 # 利用列表推倒式 对 str 类型的元素进行大小写翻转 -swapcased = [i.swapcase() for i in filtered] -print('进行大小写翻转 == >', swapcased) +swapcased = [i.swapcase() for i in filtered ] +print('进行大小写翻转 ==>', swapcased) # 4.单词按 a_z 升序排列 # print('单词按 a_z 升序排列==>', sorted(swapcased)) From 18274f656b0caf095e0fb30b89f2fec46deadea2 Mon Sep 17 00:00:00 2001 From: boy-35 Date: Thu, 22 Aug 2019 19:54:23 +0800 Subject: [PATCH 11/11] =?UTF-8?q?day6=201901100053=20=2014=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/1901100053/day5_array.py.txt | 14 ---- exercises/1901100053/day6_stats_word.py | 93 +++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 14 deletions(-) delete mode 100644 exercises/1901100053/day5_array.py.txt create mode 100644 exercises/1901100053/day6_stats_word.py diff --git a/exercises/1901100053/day5_array.py.txt b/exercises/1901100053/day5_array.py.txt deleted file mode 100644 index 3c8ed1c0b..000000000 --- a/exercises/1901100053/day5_array.py.txt +++ /dev/null @@ -1,14 +0,0 @@ -sample_list=[0,1,2,3,,5,6.7,8,9,] -reversed_list=sample_list[::-1] -print('列表翻转==>', reversed_list) -joined_str = ''.join([str(i) for i in reversed_list]) -print('翻转后的数组拼接成字符串==>', joined_str) -sliced_str = joined_str[2:8] -print('用字符串切片的方式取出第三到第八个字符==>', sliced_str) -reversed_list = sliced_str[::-1] -print('字符串翻转==>', reversed_str) -int_value = int(reversed_str) -print('转换为 int 类型==>', int _value) -print('转换为 二进制==>', bin(int_value)) -print('转换为 八进制==>', oct(int_value)) -print('转换为 十六进制==>', hex(int_value)) \ No newline at end of file diff --git a/exercises/1901100053/day6_stats_word.py b/exercises/1901100053/day6_stats_word.py new file mode 100644 index 000000000..af91c6237 --- /dev/null +++ b/exercises/1901100053/day6_stats_word.py @@ -0,0 +1,93 @@ +# 统计参数中每个英文单词出现的次数 +def stats_text_en(text): + elements = text.split() + words = [] + symbols = ',.*-!' + for element in elements: + + for symbol in symbols: + element = element.replace(symbol,'') + if len(element): + words.append(element) + + + counter = {} + word_set = set(words) + + for word in word_set: + counter[word] = words.count(word) + # 函数返回值用 return 进行返回, 如果没有 return 返回值则为 None + return sorted(counter.items(), key=lambda x: x[1], reverse=True) + + + + +# 统计参数中每个中文汉字出现的次数 +def stats_text_cn(text): + cn_characters = [] + for character in text: + # unicode 中 中文字符的范围 + if'\u4e00' <= character <= '\u9fff': + cn_characters.append(character) + counter = {} + cn_character_set = set(cn_characters) + for character in cn_character_set: + counter[character] = cn_characters.count(character) + return sorted(counter.items(), key = lambda x: x[1], reverse = True) + + +en_text=''' +The Zen Of Python ,by Tim Peters + + +Beautiful is better than ugly . +Explicit is better than implicit . +Simple is better than complex . +Complex is better than complicated . +Flat is better than nesed . +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 explicotly silenced . +In the face of ambxiguity,refuse the temptation to guess . +There should be one-- and preferably only one --obvious way to do it . +Although that way may not be obvious at first unless you're Dutch . +Now is better than never . +Although never is often better than *right* now . +If the implementation is hard to explain ,it's a bad idea . +If the implementation is easy to explain , it may be a good idea . +Namespaces are one honking great idea -- let's do more of those ! +''' + +cn_text=''' +《蟒蛇之禅》(the zen of python),蒂姆·彼得斯(tim peters)著 +美丽总比丑陋好。 +显式比隐式好。 +简单总比复杂好。 +复杂总比复杂好。 +平的比嵌套的好。 +稀疏总比密集好。 +可读性。 +特殊情况还不足以打破规则。 +虽然实用性胜过纯洁性。 +错误不应该悄无声息地过去。 +除非明确禁止。 +面对敏锐,拒绝猜测的诱惑。 +应该有一种——而且最好只有一种——显而易见的方法来做到这一点。 +不过,除非你是荷兰人,否则这种方式一开始可能并不明显。 +现在总比不做好。 +虽然从来没有比“现在”更好。 +如果实现很难解释,这是一个坏主意。 +如果实现易于解释,可能是个好主意。 +名称空间是一个很棒的主意——让我们做更多这样的事情! +''' + +# 搜索 _name_==_main_ +# 一般情况下在文件内测试 代码的时候以下面的形式进行 +if __name__ == '__main__': + en_result = stats_text_en(en_text) + cn_result = stats_text_cn(cn_text) + print('统计参数中每个英文单词出现的次数==>\n', en_result) + print('统计参数中每个中文汉字出现的次数==>\n', cn_result)