From d4546bc3ec0c7095aba8a71b09dae5e576271ec6 Mon Sep 17 00:00:00 2001 From: YangShaohan Date: Thu, 7 Nov 2019 22:28:51 +0800 Subject: [PATCH 1/4] Create 1001S02E02_hello_python.py --- 1901100207/1001S02E02_hello_python.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 1901100207/1001S02E02_hello_python.py diff --git a/1901100207/1001S02E02_hello_python.py b/1901100207/1001S02E02_hello_python.py new file mode 100644 index 000000000..00950d9ac --- /dev/null +++ b/1901100207/1001S02E02_hello_python.py @@ -0,0 +1 @@ +print('hello world') \ No newline at end of file From 389172dbef3f67d9209e0f5b83c489eee020a34c Mon Sep 17 00:00:00 2001 From: YangShaohan Date: Tue, 19 Nov 2019 09:06:53 +0800 Subject: [PATCH 2/4] Create 1001S02E03_calculator.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加减乘除运算 --- 1901100207/1001S02E03_calculator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 1901100207/1001S02E03_calculator.py diff --git a/1901100207/1001S02E03_calculator.py b/1901100207/1001S02E03_calculator.py new file mode 100644 index 000000000..68bb2463b --- /dev/null +++ b/1901100207/1001S02E03_calculator.py @@ -0,0 +1,19 @@ +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) +else operator=='-': + print(a,'-',b,'=',a-b) +else operator=='*': + print(a,'*',b,'=',a*b) +else operator=='/': + print(a,'/',b,'=',a/b) +else: + print('无效的运算符') \ No newline at end of file From d44cc30471f39cd5386f1593bad4ef010036d79d Mon Sep 17 00:00:00 2001 From: YangShaohan Date: Thu, 21 Nov 2019 08:49:38 +0800 Subject: [PATCH 3/4] Create 1001S02E04_control_flow.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 九九乘法表程序 --- 1901100207/1001S02E04_control_flow.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 1901100207/1001S02E04_control_flow.py diff --git a/1901100207/1001S02E04_control_flow.py b/1901100207/1001S02E04_control_flow.py new file mode 100644 index 000000000..4435a1bfe --- /dev/null +++ b/1901100207/1001S02E04_control_flow.py @@ -0,0 +1,18 @@ +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 13601361e8b22dfba7b70ea1d46e16e1fc9183ee Mon Sep 17 00:00:00 2001 From: YangShaohan Date: Mon, 25 Nov 2019 23:18:01 +0800 Subject: [PATCH 4/4] 1001S02E05 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 字符串的基本处理和数组操作 --- 1901100207/1001S02E05_array.py | 18 +++++++++++++ 1901100207/1001S02E05_stats_text.py | 40 +++++++++++++++++++++++++++++ 1901100207/1001S02E05_string.py | 38 +++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 1901100207/1001S02E05_array.py create mode 100644 1901100207/1001S02E05_stats_text.py create mode 100644 1901100207/1001S02E05_string.py diff --git a/1901100207/1001S02E05_array.py b/1901100207/1001S02E05_array.py new file mode 100644 index 000000000..02a6a4c5c --- /dev/null +++ b/1901100207/1001S02E05_array.py @@ -0,0 +1,18 @@ +sample_list=[0,1,2,3,4,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_str=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/1901100207/1001S02E05_stats_text.py b/1901100207/1001S02E05_stats_text.py new file mode 100644 index 000000000..ba23c62c8 --- /dev/null +++ b/1901100207/1001S02E05_stats_text.py @@ -0,0 +1,40 @@ +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() +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)) \ No newline at end of file diff --git a/1901100207/1001S02E05_string.py b/1901100207/1001S02E05_string.py new file mode 100644 index 000000000..1fd2581ab --- /dev/null +++ b/1901100207/1001S02E05_string.py @@ -0,0 +1,38 @@ +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! +''' + +text = sample_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))