From 1c27c5575a0131b81a78f921c2259a38989c58fa Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Wed, 14 Aug 2019 18:24:30 +0800 Subject: [PATCH 1/8] commit commit --- exercises/1901100290/1001S02E01_helloworld.txt | 1 + exercises/1901100290/readme.md | 1 + 2 files changed, 2 insertions(+) create mode 100644 exercises/1901100290/1001S02E01_helloworld.txt create mode 100644 exercises/1901100290/readme.md diff --git a/exercises/1901100290/1001S02E01_helloworld.txt b/exercises/1901100290/1001S02E01_helloworld.txt new file mode 100644 index 000000000..46450b5ed --- /dev/null +++ b/exercises/1901100290/1001S02E01_helloworld.txt @@ -0,0 +1 @@ +1001S02E01_helloworld.txt 
 diff --git a/exercises/1901100290/readme.md b/exercises/1901100290/readme.md new file mode 100644 index 000000000..ea786ff2c --- /dev/null +++ b/exercises/1901100290/readme.md @@ -0,0 +1 @@ +readme \ No newline at end of file From 74913479704eb5fdaf34b390dce1fa645973800d Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Wed, 14 Aug 2019 18:56:41 +0800 Subject: [PATCH 2/8] day1 --- exercises/1901100290/README .md | 6 ++++++ exercises/1901100290/readme.md | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 exercises/1901100290/README .md delete mode 100644 exercises/1901100290/readme.md diff --git a/exercises/1901100290/README .md b/exercises/1901100290/README .md new file mode 100644 index 000000000..8ccd73d9d --- /dev/null +++ b/exercises/1901100290/README .md @@ -0,0 +1,6 @@ +# 自学 Python 训练营 + + + +涅槃作业仓库 +(https://github.com/selfteaching-learning-notes/selfteaching-learning-notes.github.io) diff --git a/exercises/1901100290/readme.md b/exercises/1901100290/readme.md deleted file mode 100644 index ea786ff2c..000000000 --- a/exercises/1901100290/readme.md +++ /dev/null @@ -1 +0,0 @@ -readme \ No newline at end of file From 2827e7bea595810bfb20d5c769861944c794dd03 Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Thu, 15 Aug 2019 11:37:18 +0800 Subject: [PATCH 3/8] d2 --- exercises/1901100290/1001S02E02_hello_python.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 exercises/1901100290/1001S02E02_hello_python.py diff --git a/exercises/1901100290/1001S02E02_hello_python.py b/exercises/1901100290/1001S02E02_hello_python.py new file mode 100644 index 000000000..e75154b7c --- /dev/null +++ b/exercises/1901100290/1001S02E02_hello_python.py @@ -0,0 +1 @@ +print("hello world") \ No newline at end of file From b2391bbc968d4b5148c02d47b046e31a95905b79 Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Fri, 16 Aug 2019 22:49:28 +0800 Subject: [PATCH 4/8] d3 --- exercises/1901100290/1001S02E03_calculator.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 exercises/1901100290/1001S02E03_calculator.py diff --git a/exercises/1901100290/1001S02E03_calculator.py b/exercises/1901100290/1001S02E03_calculator.py new file mode 100644 index 000000000..8f313fd16 --- /dev/null +++ b/exercises/1901100290/1001S02E03_calculator.py @@ -0,0 +1,13 @@ +a = float(input('Please enter a number: ')) +option = input('Please enter a operator: ') +b = float(input('Please enter another number: ')) +if option == '+': + print("result: ",a+b) +if option == '-': + print("result: ",a-b) +if option == '*': + print("result: ",a*b) +if option == '/': + print("result: ",a/b) + + From 38a2e54ba1270b9fac9583a25677f4d81ff7540f Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Tue, 20 Aug 2019 17:38:49 +0800 Subject: [PATCH 5/8] d4 --- exercises/1901100290/1001S02E04_control_flow.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 exercises/1901100290/1001S02E04_control_flow.py diff --git a/exercises/1901100290/1001S02E04_control_flow.py b/exercises/1901100290/1001S02E04_control_flow.py new file mode 100644 index 000000000..ef33ab4e4 --- /dev/null +++ b/exercises/1901100290/1001S02E04_control_flow.py @@ -0,0 +1,16 @@ +for i in range(1, 10): + for j in range(1, i+1): + print('{}×{}={}'.format(j, i, i*j), end='\t') + print() + + i = 1 +while i < 10: + j = 1 + while j<=i: + if i%2 == 0: + break + print('{}*{}={}'.format(i,j,i*j),end='\t') + j +=1 + i +=1 + print() + \ No newline at end of file From afd9d20c145ec9c8b2c77eb0f6158d14d2a73439 Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Tue, 3 Sep 2019 09:26:37 +0800 Subject: [PATCH 6/8] D5 --- exercises/1901100290/1001S02E05_array.py | 29 ++++++++++++ exercises/1901100290/1001S02E05_stats_text.py | 35 +++++++++++++++ exercises/1901100290/1001S02E05_string.py | 44 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 exercises/1901100290/1001S02E05_array.py create mode 100644 exercises/1901100290/1001S02E05_stats_text.py create mode 100644 exercises/1901100290/1001S02E05_string.py diff --git a/exercises/1901100290/1001S02E05_array.py b/exercises/1901100290/1001S02E05_array.py new file mode 100644 index 000000000..b4abb180d --- /dev/null +++ b/exercises/1901100290/1001S02E05_array.py @@ -0,0 +1,29 @@ + +# 翻转 +p=[0,1,2,3,4,5,6,7,8,9] +p.reverse() +print(p) + +#翻转后的数组拼接成字符串串 + +y = ''.join(str(i) for i in p) + +#⽤用字符串串切⽚片的⽅方式取出第三到第⼋八个字符(包含第三和第⼋八个字符) + +a = y[2:8] + +#将获得的字符串串进⾏行行翻转 + +c = a[::-1] + +# 将结果转换为int类型 + +b = int(c) + +# 分别转换成⼆二进制,⼋八进制,⼗十六进制 + +print('十进制整数为: ',b) +print('转换成二进制为: ',bin(b)) +print('转换成八进制为: ',oct(b)) +print('转换成十六进制为: ',hex(b)) + diff --git a/exercises/1901100290/1001S02E05_stats_text.py b/exercises/1901100290/1001S02E05_stats_text.py new file mode 100644 index 000000000..87f000e9d --- /dev/null +++ b/exercises/1901100290/1001S02E05_stats_text.py @@ -0,0 +1,35 @@ +text = ''' +The Zen of Python, by Tim Peters + +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + + + + +s = {} +for n in text.split(): + if not n in s: + s[n] = 1 + else: + s[n] = s[n]+1 +print(s) + \ No newline at end of file diff --git a/exercises/1901100290/1001S02E05_string.py b/exercises/1901100290/1001S02E05_string.py new file mode 100644 index 000000000..b954e47c2 --- /dev/null +++ b/exercises/1901100290/1001S02E05_string.py @@ -0,0 +1,44 @@ +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 +s = text.replace('better','worse') +print(s) + +#2.剔除含有ea的单词 +a="EA" +b=[] +for a in s: + if a.find(s)<0: + b.append(a) +print(s) + +#3.大小写替换 +y=s.swapcase() +print(y) + +#4.升序排列 +list1=y.split() +list1.sort() +print(list1) \ No newline at end of file From ef1b53580fb22ea2464128f3427ad24a7a45089b Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Mon, 9 Sep 2019 14:44:10 +0800 Subject: [PATCH 7/8] D5 D5 --- exercises/1901100290/1001S02E05_array.py | 9 +++++++ exercises/1901100290/1001S02E05_stats_text.py | 27 +++++++++++++------ exercises/1901100290/1001S02E05_string.py | 3 +++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/exercises/1901100290/1001S02E05_array.py b/exercises/1901100290/1001S02E05_array.py index b4abb180d..77e64667d 100644 --- a/exercises/1901100290/1001S02E05_array.py +++ b/exercises/1901100290/1001S02E05_array.py @@ -1,25 +1,31 @@ # 翻转 + p=[0,1,2,3,4,5,6,7,8,9] p.reverse() print(p) + #翻转后的数组拼接成字符串串 y = ''.join(str(i) for i in p) + #⽤用字符串串切⽚片的⽅方式取出第三到第⼋八个字符(包含第三和第⼋八个字符) a = y[2:8] + #将获得的字符串串进⾏行行翻转 c = a[::-1] + # 将结果转换为int类型 b = int(c) + # 分别转换成⼆二进制,⼋八进制,⼗十六进制 print('十进制整数为: ',b) @@ -27,3 +33,6 @@ print('转换成八进制为: ',oct(b)) print('转换成十六进制为: ',hex(b)) +int('b', 2) +int('b', 8) +int('b', 16) diff --git a/exercises/1901100290/1001S02E05_stats_text.py b/exercises/1901100290/1001S02E05_stats_text.py index 87f000e9d..bf7a4cac2 100644 --- a/exercises/1901100290/1001S02E05_stats_text.py +++ b/exercises/1901100290/1001S02E05_stats_text.py @@ -25,11 +25,22 @@ -s = {} -for n in text.split(): - if not n in s: - s[n] = 1 - else: - s[n] = s[n]+1 -print(s) - \ No newline at end of file + + +# 只统计英文单词,不包括非英文字符的其他任何符号,如连接符号、空白字符等等 +list1 = text.split( ) +i=0 +for i in range(0,len(list1)): + list1[i]=list1[i].strip('*-,.!') + if list1[i]==' ': + list1[i].remove(' ') + else: + i=i+1 +# 使用dict统计字符串样本中各个英文单词出现的次数 +# 按照出现次数从大到小排列,示例 {'is': 10, ‘better’ : 9, …… } +import collections +print(collections.Counter(list1)) + + + + diff --git a/exercises/1901100290/1001S02E05_string.py b/exercises/1901100290/1001S02E05_string.py index b954e47c2..784cb915a 100644 --- a/exercises/1901100290/1001S02E05_string.py +++ b/exercises/1901100290/1001S02E05_string.py @@ -26,6 +26,7 @@ s = text.replace('better','worse') print(s) + #2.剔除含有ea的单词 a="EA" b=[] @@ -34,10 +35,12 @@ b.append(a) print(s) + #3.大小写替换 y=s.swapcase() print(y) + #4.升序排列 list1=y.split() list1.sort() From e4480c2e72d40e85669f6a129759a56879c385a5 Mon Sep 17 00:00:00 2001 From: niepanzhang <2220303257@qq.com> Date: Sun, 22 Sep 2019 20:14:31 +0800 Subject: [PATCH 8/8] D6 d6 --- exercises/1901100290/1001S02E06_stats_word.py | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 exercises/1901100290/1001S02E06_stats_word.py diff --git a/exercises/1901100290/1001S02E06_stats_word.py b/exercises/1901100290/1001S02E06_stats_word.py new file mode 100644 index 000000000..59c7dc51e --- /dev/null +++ b/exercises/1901100290/1001S02E06_stats_word.py @@ -0,0 +1,97 @@ +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! +''' + +elements=sample_text.split()#先将字符串根据空白字符分割成list,要调用str类型 +words=[]#定义一个新的list型变量,存储处理过的单词 +symbols=',.*-!'#针对文本筛选出需要剔除的非单词符号 + +for element in elements: + for symbol in symbols:#遍一遍需要剔除的符号 + element=element.replace(symbol,'')#逐个替换字符号,用‘’是为了同时剔除符号所占的位置 + if len(element): + words.append(element)#剔除了字符后如果element的长度不为0,则算作正常单词 +print('',words) + +counter = {}#初始化一个dict(字典)类型的变量,用来存放单词出现的次数 +word_set = set(words)#set(集合)类型可以去掉列表里的重复元素 +for word in word_set: + counter[word] = word.count(word) +print('',counter)#在for··in里减少循环次数 +print('',sorted(counter.items(),key=lambda x:x[1],reverse=True)) +#按照出现次数从大到小输出所有的单词及出现次数 +#内置函数sorted的参数key表示按元素的哪一项进行排序 +#dict类型counter的items方法会返回一个包含相应项(key,value)的元素列表 +#print('counter.items()‘,counter.items()) + +sample_text = ''' +The Zen of Python, by Tim Peters + +美 丽 优 于 丑 陋. +直 言 优 于 暗 示. +简 单 优 于 复 杂. +复 杂 优 于 难 懂. +平 直 优 于 曲 折. +疏 散 优 于 密 集. +重 在 重 读. +打 破 规 则 的 特 别 不 能 称 之 为 特 别. +尽 管 练 习 会 打 败 纯 粹. +错 误 不 应 该 无 声 的 过 去. +除 非 明 晰 沉 默. +直 面 拒 绝 猜 测. +这 将 只 有 一 个-- 完 美 的 仅 有 的 --显 然 易 见 的 路 去 做. +尽 管 那 条 路 一 开 始 并 不 明 显 除 非 你 延 展. +现 在 好 过 从 不. +尽 管 从 不 常 好 过 *对 的* 现 在. +如 果 执 行 很 难 解 释,那 也 许 是 坏 点 子. +如 果 执 行 很 易 解 释,那 也 许 是 好 点 子. +命 名 空 间 是 最 棒 的 想 法 -- 让 我 们 做 的 更 多! +''' + +elements=sample_text.split()#先将字符串根据空白字符分割成list,要调用str类型 +words=[]#定义一个新的list型变量,存储处理过的单词 +symbols=',.*-!'#针对文本筛选出需要剔除的非单词符号 + +for element in elements: + for symbol in symbols:#遍一遍需要剔除的符号 + element=element.replace(symbol,'')#逐个替换字符号,用‘’是为了同时剔除符号所占的位置 + if len(element): + words.append(element)#剔除了字符后如果element的长度不为0,则算作正常单词 +print('',words) + +counter = {}#初始化一个dict(字典)类型的变量,用来存放单词出现的次数 +word_set = set(words)#set(集合)类型可以去掉列表里的重复元素 +for word in word_set: + counter[word] = word.count(word) +print('',counter)#在for··in里减少循环次数 +print('',sorted(counter.items(),key=lambda x:x[1],reverse=True)) +#按照出现次数从大到小输出所有的单词及出现次数 +#内置函数sorted的参数key表示按元素的哪一项进行排序 +#dict类型counter的items方法会返回一个包含相应项(key,value)的元素列表 +#print('counter.items()‘,counter.items()) + + + + + +