From 5e41ca6818b75af785cb317c27229379c55645e8 Mon Sep 17 00:00:00 2001 From: oneisonly <532276567@qq.com> Date: Thu, 12 Sep 2019 16:55:20 +0800 Subject: [PATCH 1/7] day2 --- exercises/1901100166/1001S02E02_hello_python.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 exercises/1901100166/1001S02E02_hello_python.py diff --git a/exercises/1901100166/1001S02E02_hello_python.py b/exercises/1901100166/1001S02E02_hello_python.py new file mode 100644 index 000000000..00950d9ac --- /dev/null +++ b/exercises/1901100166/1001S02E02_hello_python.py @@ -0,0 +1 @@ +print('hello world') \ No newline at end of file From ec46fe0217ad9305a75fd6b19a4fcb989fa37e59 Mon Sep 17 00:00:00 2001 From: oneisonly <53245383+oneisonly@users.noreply.github.com> Date: Thu, 31 Oct 2019 14:29:36 +0800 Subject: [PATCH 2/7] day3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 辛苦老师了,第一个是视频里讲的,打印正常,第二个是我做了个简单的,但打印不出来 --- exercises/1901100166/1001s02e03_calculator.py | 23 +++++++++++++++++++ .../1901100166/1001s02e03_calculator1.py | 14 +++++++++++ 2 files changed, 37 insertions(+) create mode 100644 exercises/1901100166/1001s02e03_calculator.py create mode 100644 exercises/1901100166/1001s02e03_calculator1.py diff --git a/exercises/1901100166/1001s02e03_calculator.py b/exercises/1901100166/1001s02e03_calculator.py new file mode 100644 index 000000000..e3f3a1ba1 --- /dev/null +++ b/exercises/1901100166/1001s02e03_calculator.py @@ -0,0 +1,23 @@ +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) + +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('无效的运算符') diff --git a/exercises/1901100166/1001s02e03_calculator1.py b/exercises/1901100166/1001s02e03_calculator1.py new file mode 100644 index 000000000..e4dae7eee --- /dev/null +++ b/exercises/1901100166/1001s02e03_calculator1.py @@ -0,0 +1,14 @@ +fuhao = input"请输入运算符号(+,-,*,/):" +a=int(input("请输入第一个数字")) +b=int(input("请输入第二个数字")) + +if fuhao == '+': + print(a + b) +elif fuhao == '-': + print(a - b) +elif fuhao == '*': + print(a * b) +elif fuhao == '/': + print(a / b) +else: + print('无效的运算符') \ No newline at end of file From 0bedf88240c80d45651ea3f6f5d8037c1767c523 Mon Sep 17 00:00:00 2001 From: oneisonly <53245383+oneisonly@users.noreply.github.com> Date: Thu, 31 Oct 2019 15:11:59 +0800 Subject: [PATCH 3/7] day3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改了一下 --- exercises/1901100166/1001s02e03_calculator1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/1901100166/1001s02e03_calculator1.py b/exercises/1901100166/1001s02e03_calculator1.py index e4dae7eee..a0d5bdd53 100644 --- a/exercises/1901100166/1001s02e03_calculator1.py +++ b/exercises/1901100166/1001s02e03_calculator1.py @@ -1,4 +1,4 @@ -fuhao = input"请输入运算符号(+,-,*,/):" +fuhao = input("请输入运算符号(+,-,*,/):") a=int(input("请输入第一个数字")) b=int(input("请输入第二个数字")) From 735dd8be298200de216d091a5e2e217ec9842a0f Mon Sep 17 00:00:00 2001 From: oneisonly <53245383+oneisonly@users.noreply.github.com> Date: Mon, 11 Nov 2019 16:33:52 +0800 Subject: [PATCH 4/7] d4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两种方法 --- .../1901100166/1001s02e04_control_flow.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 exercises/1901100166/1001s02e04_control_flow.py diff --git a/exercises/1901100166/1001s02e04_control_flow.py b/exercises/1901100166/1001s02e04_control_flow.py new file mode 100644 index 000000000..f343caa0d --- /dev/null +++ b/exercises/1901100166/1001s02e04_control_flow.py @@ -0,0 +1,42 @@ + +print('打印九九乘法表') +for i in range(1,10): + print('第%d行'%i,end='\t') + for j in range(1,i+1): + + print('{}*{}={}'.format(i,j,i*j),end='\t') + print() + +print('\n\n打印奇数行九九乘法表') + +i=1 +while i<10: + if i%2==0: + print('跳过第%d行'%i) + else: + print('第%d行'%i,end='\t') + for j in range(1,i+1): + + print('{}*{}={}'.format(i,j,i*j),end='\t') + print() + i+=1 + +# 用for in 打印九九乘法口诀表 +for a in range(1,10): + for b in range(1,a+1): + print(a,'*',b,'=',a*b,end="\t") + print() + + +print() + +# 用While 打印九九乘法表并用条件判断把偶数⾏行行去除掉 +a=1 +while a<10: + if a%2>0: + b=1 + while b',fanzhuan_list) #此时是int类型元素 + +#2. + +A=''.join([str(j)for j in fanzhuan_list]) #''符号表示元素间不用任何字符隔开 + #转换成str类型 的列表 +print('翻转后的数组拼接成字符串==>',A) + +#3. +b_str=A[2:8] +print('用字符串切片的方式取出第三到八个字符==>',b_str) + +#4. +C=b_str[::-1] +print('切片字符串翻转==>',C) + +#5. +E=int(C) + +print('转为int类型==》',E) + +print('转为 二进制==》',bin(E)) +print('转为 八进制==》',oct(E)) +print('转为 十六进制==》',hex(E)) \ No newline at end of file diff --git a/exercises/1901100166/1001s02e05_stats_text.py b/exercises/1901100166/1001s02e05_stats_text.py new file mode 100644 index 000000000..8b1b4cc70 --- /dev/null +++ b/exercises/1901100166/1001s02e05_stats_text.py @@ -0,0 +1,51 @@ +a = ''' +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.使用字典dict类型统计单词出现次数 + +A=a.split() #字符串分割成list +B=[] #定义新的list型变量,储存处理后的单词 +C=',.*-!' #选出样本中要剔除的非单词符号 + +for AA in A: #遍历一遍要剔除的符号 + for CC in C: #逐个替换字符号,用''是为了同时剔除符号所占位置 + AA=AA.replace(CC,'') #剔除字符后如果AA的长度不为0,则算正常单词 + if len(AA): + B.append(AA) + +print('纯单词==>',B) + +counter={} #初始化一个dict类型的变量,来存放单词出现次数 + +B_set=set(B) #set(集合)使重复的元素只出现1次,减少在for in 里的循环次数 + +for BB in B_set: + counter[BB]=B.count(BB) #BB是对单词的项进行赋值,表明单词出现多少次 + +print('单词次数==>',counter) + +#2. +print('从大到小==>',sorted(counter.items(),key=lambda x:x[1],reverse=True)) + +#E.items() 是一个字典的方法,会返回一个列表即含(key,value)的 元组,我们是在对此列表排序, +# key指单词,value指单词出现的次数,lambda函数取第一项 \ No newline at end of file diff --git a/exercises/1901100166/1001s02e05_string.py b/exercises/1901100166/1001s02e05_string.py new file mode 100644 index 000000000..8b15ab597 --- /dev/null +++ b/exercises/1901100166/1001s02e05_string.py @@ -0,0 +1,50 @@ +a = ''' +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 方法进行替换 +b= a.replace('better','worse') +#print('将字符串样本里的 better 全部替换成 worse ==>', b) + +#2. +c=a.split() #调用str类型,将字符串 根据 空白字符 分割成list +guolv=[] #定义list类型的变量存放过滤后的单词 +for d in c: #句型判断是否含ea + if d.find('ea')<2: # str类型的find方法 不含参数则返回-1,含则返回第一次出现的索引 + guolv.append(d) +print('剔除ea',guolv) + +#3.大小写翻转 +E=[e.swapcase() for e in guolv] +#print('333333',E) + +#4.单词升序排列 +#print('升序==>',sorted(E)) #sorted默认升序 + +#print('降序==>',sorted(E, reverse=True)) + + + + + From cceebb34a387150388b5d830bd38520e95a54c6f Mon Sep 17 00:00:00 2001 From: oneisonly <53245383+oneisonly@users.noreply.github.com> Date: Mon, 25 Nov 2019 15:49:55 +0800 Subject: [PATCH 6/7] d6 --- exercises/1901100166/1001s02e06_stats_word.py | 67 +++++++++++++++++++ exercises/1901100166/111.py/111.py | 11 +++ 2 files changed, 78 insertions(+) create mode 100644 exercises/1901100166/1001s02e06_stats_word.py create mode 100644 exercises/1901100166/111.py/111.py diff --git a/exercises/1901100166/1001s02e06_stats_word.py b/exercises/1901100166/1001s02e06_stats_word.py new file mode 100644 index 000000000..0d6206599 --- /dev/null +++ b/exercises/1901100166/1001s02e06_stats_word.py @@ -0,0 +1,67 @@ + #统计英文单词出现次数 +def stats_text_en(a): + A=a.split() + B=[] + C=',.*-!' + + for AA in A: + for CC in C: + AA=AA.replace(CC,'') + if len(AA): + B.append(AA) + counter={} + B_set=set(B) + + for BB in B_set: + counter[BB]=B.count(BB) + #函数返回值用return进行返回,如果没有return,则返回值为none + return sorted(counter.items(),key=lambda x: x[1],reverse=True) + #在一个完整的文件里是不能用return值,在函数里可以用? + + + #统计中文汉字次数 + +def cn(b): + cn_character=[] + for character in b: + if'\u4e00'<=character<='\u9fff': #汉字在unicode中都有对应固定的值 + cn_character.append(character) + counter={} + cn=set(cn_character) + for character in cn: + counter[character]=cn_character.count(character) + return sorted(counter.items(),key=lambda x:x[1],reverse=True) + + + +a= ''' +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! +''' + + + +b='我爱北京天安门!' + +#if __name__ == "__main__": #这个公式作用:防止在引用这个文件时不运行此代码 + +print('英文次数==>\n',stats_text_en(a)) +print('中文次数==>\n',cn(b)) \ No newline at end of file diff --git a/exercises/1901100166/111.py/111.py b/exercises/1901100166/111.py/111.py new file mode 100644 index 000000000..dc001202f --- /dev/null +++ b/exercises/1901100166/111.py/111.py @@ -0,0 +1,11 @@ +a='123456789e' + +b=a.split() + +print(b) + +c=a.replace('1','9') +print(c) + +d=a.swapcase() +print(d) \ No newline at end of file From 60efa2d9e1735a4679ea15300122a876a0c84a56 Mon Sep 17 00:00:00 2001 From: oneisonly <53245383+oneisonly@users.noreply.github.com> Date: Mon, 25 Nov 2019 15:52:52 +0800 Subject: [PATCH 7/7] day6 --- exercises/1901100166/1001s02e05_array.py | 2 +- exercises/1901100166/1001s02e05_string.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exercises/1901100166/1001s02e05_array.py b/exercises/1901100166/1001s02e05_array.py index 1cb898318..290114059 100644 --- a/exercises/1901100166/1001s02e05_array.py +++ b/exercises/1901100166/1001s02e05_array.py @@ -12,7 +12,7 @@ #3. b_str=A[2:8] -print('用字符串切片的方式取出第三到八个字符==>',b_str) +print('用字符串切片的方式取出第三到八个字符==>',b_str) #从0 开始算第一个字符 #4. C=b_str[::-1] diff --git a/exercises/1901100166/1001s02e05_string.py b/exercises/1901100166/1001s02e05_string.py index 8b15ab597..3637d5574 100644 --- a/exercises/1901100166/1001s02e05_string.py +++ b/exercises/1901100166/1001s02e05_string.py @@ -25,22 +25,22 @@ # 调用 str 类型 的 replace 方法进行替换 b= a.replace('better','worse') -#print('将字符串样本里的 better 全部替换成 worse ==>', b) +print('将字符串样本里的 better 全部替换成 worse ==>', b) #2. c=a.split() #调用str类型,将字符串 根据 空白字符 分割成list guolv=[] #定义list类型的变量存放过滤后的单词 for d in c: #句型判断是否含ea - if d.find('ea')<2: # str类型的find方法 不含参数则返回-1,含则返回第一次出现的索引 + if d.find('ea')<0: # str类型的find方法 不含参数则返回-1,含则返回第一次出现的索引 guolv.append(d) -print('剔除ea',guolv) +print('剔除ea==>',guolv) #3.大小写翻转 E=[e.swapcase() for e in guolv] -#print('333333',E) +print('333333',E) #4.单词升序排列 -#print('升序==>',sorted(E)) #sorted默认升序 +print('升序==>',sorted(E)) #sorted默认升序 #print('降序==>',sorted(E, reverse=True))