From 6270aabe3a44299e3286b30288fe7f711d2c4458 Mon Sep 17 00:00:00 2001 From: Sandra-Zhang Date: Fri, 8 Nov 2019 15:30:10 +0800 Subject: [PATCH 1/6] 1001S02E01 --- exercises/1901100067/1001S02E01_helloworld.txt | 1 + exercises/1901100067/README.md | 0 2 files changed, 1 insertion(+) create mode 100644 exercises/1901100067/1001S02E01_helloworld.txt create mode 100644 exercises/1901100067/README.md diff --git a/exercises/1901100067/1001S02E01_helloworld.txt b/exercises/1901100067/1001S02E01_helloworld.txt new file mode 100644 index 000000000..75c16985b --- /dev/null +++ b/exercises/1901100067/1001S02E01_helloworld.txt @@ -0,0 +1 @@ +New starting \ No newline at end of file diff --git a/exercises/1901100067/README.md b/exercises/1901100067/README.md new file mode 100644 index 000000000..e69de29bb From 0eb2bef97e79f54d17424b8514d617b1e446168f Mon Sep 17 00:00:00 2001 From: Sandra-zhang <48641570+Sandra-zhang@users.noreply.github.com> Date: Mon, 11 Nov 2019 15:16:03 +0800 Subject: [PATCH 2/6] Create 1001S02E02_hello_python.py --- exercises/1901100067/1001S02E02_hello_python.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 exercises/1901100067/1001S02E02_hello_python.py diff --git a/exercises/1901100067/1001S02E02_hello_python.py b/exercises/1901100067/1001S02E02_hello_python.py new file mode 100644 index 000000000..7da2b9121 --- /dev/null +++ b/exercises/1901100067/1001S02E02_hello_python.py @@ -0,0 +1,3 @@ +#hello world +#author:Sandra.Z +print ('hello world') \ No newline at end of file From 310fafe22ecbcb81d7faeeae3e38e92bf1abab29 Mon Sep 17 00:00:00 2001 From: Sandra-zhang <48641570+Sandra-zhang@users.noreply.github.com> Date: Tue, 12 Nov 2019 15:09:51 +0800 Subject: [PATCH 3/6] Create 1001S02E03_calculator.py --- exercises/1901100067/1001S02E03_calculator.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 exercises/1901100067/1001S02E03_calculator.py diff --git a/exercises/1901100067/1001S02E03_calculator.py b/exercises/1901100067/1001S02E03_calculator.py new file mode 100644 index 000000000..edcf848b9 --- /dev/null +++ b/exercises/1901100067/1001S02E03_calculator.py @@ -0,0 +1,23 @@ +# calculator +# author:Sandra.Z +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)) + +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('无效的运算符') \ No newline at end of file From 8dff8f723af2726c26be22a334552430efa1497d Mon Sep 17 00:00:00 2001 From: Sandra-zhang <48641570+Sandra-zhang@users.noreply.github.com> Date: Wed, 13 Nov 2019 00:34:23 +0800 Subject: [PATCH 4/6] Create 1001S02E04_control_flow.py --- .../1901100067/1001S02E04_control_flow.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 exercises/1901100067/1001S02E04_control_flow.py diff --git a/exercises/1901100067/1001S02E04_control_flow.py b/exercises/1901100067/1001S02E04_control_flow.py new file mode 100644 index 000000000..1a73f82c6 --- /dev/null +++ b/exercises/1901100067/1001S02E04_control_flow.py @@ -0,0 +1,18 @@ +# 九九乘法表 +# author:Sandra.Z +print('九九乘法表') +for x in range(1, 10): + print(x, end= '\t') + for y in range(1, x+1): + print(x, '*', y, '=', x*y, end='\t') + print() + +print('跳过偶数行的九九乘法表') +x = 1 +while x < 10: + if x % 2 == 0: + print() + else: + for y in range(1, x+1): + print(x, '*', y, '=', x*y, end='\t') + x += 1 \ No newline at end of file From 2bd7e1e12b4dadabc5a2f6a5f6bab4649bc6aa07 Mon Sep 17 00:00:00 2001 From: Sandra-zhang <48641570+Sandra-zhang@users.noreply.github.com> Date: Mon, 18 Nov 2019 00:30:16 +0800 Subject: [PATCH 5/6] 1001S02E05_WORK --- exercises/1901100067/1001S02E05_array.py | 25 ++++++++++ exercises/1901100067/1001S02E05_stats_text.py | 50 +++++++++++++++++++ exercises/1901100067/1001S02E05_string.py | 40 +++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 exercises/1901100067/1001S02E05_array.py create mode 100644 exercises/1901100067/1001S02E05_stats_text.py create mode 100644 exercises/1901100067/1001S02E05_string.py diff --git a/exercises/1901100067/1001S02E05_array.py b/exercises/1901100067/1001S02E05_array.py new file mode 100644 index 000000000..380f0aa8c --- /dev/null +++ b/exercises/1901100067/1001S02E05_array.py @@ -0,0 +1,25 @@ +# array +# author:Sandra.Z + +sample_list=[0,1,2,3,4,5,6,7,8,9] +reversed_list=sample_list[::-1] +print('列表翻转==>',reversed_list) +print() + +joined_str=''.join([str(i)for i in reversed_list]) +print('反转后的数组拼接成字符串==>',joined_str) +print() + +sliced_str=joined_str[2:8] +print('用字符串切片的方式取出第三到第八个字符==>',sliced_str) +print() + +reversed_str=sliced_str[::-1] +print('字符串翻转==>',reversed_str) +print() + +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/1901100067/1001S02E05_stats_text.py b/exercises/1901100067/1001S02E05_stats_text.py new file mode 100644 index 000000000..c1b556068 --- /dev/null +++ b/exercises/1901100067/1001S02E05_stats_text.py @@ -0,0 +1,50 @@ +# stats +# author:Sandra.Z +text = ''' +The Zen of Python, by Tim Peters + +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +elements = text.split() + +words = [] + +symbols = ',.*-!' + +for element in elements: + for symbol in symbols: + element = element.replace(symbol, '') + if len(element): + words.append(element) +print('正常的英文单词 ==>', words) + +counter = {} + +word_set = set(words) + +for word in word_set: + counter[word] = words.count(word) +print('英文单词出现的次数 ==>', counter) + +print('从大到小输出所有的单词及出现的次数 ==>', sorted(counter.items(), key = lambda x:x[1], reverse = True)) + + diff --git a/exercises/1901100067/1001S02E05_string.py b/exercises/1901100067/1001S02E05_string.py new file mode 100644 index 000000000..b1aee4900 --- /dev/null +++ b/exercises/1901100067/1001S02E05_string.py @@ -0,0 +1,40 @@ +# string +# author:Sandra.Z +text = ''' +The Zen of Python, by Tim Peters + +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +text=text.replace('better', 'worse') +print('将字符串样本里的 better 全部换成 worse ==>', text) + +words = text.split() +filtered = [] +for word in words: + if word.find('ea') < 0: + filtered.append(word) +print('将单词中包含 ea 的单词剔除 ==>', filtered) + +swapcased = [i.swapcase() for i in filtered] +print('进行大小写翻转 ==>', swapcased) + +print('单词按 a...z 升序排列 ==>', sorted(swapcased)) From 9c657b78ee384adc0752230ca5e2fbb65f49c4c5 Mon Sep 17 00:00:00 2001 From: Sandra-zhang <48641570+Sandra-zhang@users.noreply.github.com> Date: Wed, 20 Nov 2019 00:10:44 +0800 Subject: [PATCH 6/6] 1001S02E06_stats_word.py --- exercises/1901100067/1001S02E05_array.py | 1 - exercises/1901100067/1001S02E06_stats_word.py | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 exercises/1901100067/1001S02E06_stats_word.py diff --git a/exercises/1901100067/1001S02E05_array.py b/exercises/1901100067/1001S02E05_array.py index 380f0aa8c..c2d593ef5 100644 --- a/exercises/1901100067/1001S02E05_array.py +++ b/exercises/1901100067/1001S02E05_array.py @@ -1,6 +1,5 @@ # array # author:Sandra.Z - sample_list=[0,1,2,3,4,5,6,7,8,9] reversed_list=sample_list[::-1] print('列表翻转==>',reversed_list) diff --git a/exercises/1901100067/1001S02E06_stats_word.py b/exercises/1901100067/1001S02E06_stats_word.py new file mode 100644 index 000000000..f5cb050ec --- /dev/null +++ b/exercises/1901100067/1001S02E06_stats_word.py @@ -0,0 +1,83 @@ +# stats_word +# author:Sandra.Z +def stats_text_en(text): + elements=text.split() + words=[] + symbols=',.*-!' + for element in elements: + for symbol in symbols: + element=element.replace(symbol,'') + if len(element): + words.append(element) + counter={} + word_set=set(words) + + for word in word_set: + counter[word]=words.count(word) + + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + + +def stats_text_cn(text): + cn_characters=[] + for character in text: + if '\u4e00'<= character <='\u9fff': + cn_characters.append(character) + counter={} + cn_characters_set=set(cn_characters) + for character in cn_characters_set: + counter[character]=cn_characters.count(character) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + + +en_text=''' +The Zen of Python, by Tim Peters + + +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambxiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do +it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +''' + +cn_text=''' +python之禅 by Tim Peters + +优美胜于丑陋 +明了胜于晦涩 +简洁胜于复杂 +复杂胜于凌乱 +扁平胜于嵌套 +间隔胜于紧凑 +可读性很重要 +即便假借特例的实用性之名,也不可违背这些规则 +不要包容所有错误,除非你确定需要这样做 +当存在多种可能,不要尝试去猜测 +而是尽量找一种,最好是唯一一种明显的解决方案 +虽然这并不容易,因为你不是python之父 +做也许好过不做,但不假思索就动手还不如不做 +。。。 +''' + + +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)