diff --git a/exercises/1901100191/1001S02E03_calculator.py b/exercises/1901100191/1001S02E03_calculator.py new file mode 100644 index 000000000..466688c42 --- /dev/null +++ b/exercises/1901100191/1001S02E03_calculator.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)) +print('second_number:', second_number, type(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('无效运算符') \ No newline at end of file diff --git a/exercises/1901100191/1001S02E06_stats_word.py b/exercises/1901100191/1001S02E06_stats_word.py new file mode 100644 index 000000000..7365384e9 --- /dev/null +++ b/exercises/1901100191/1001S02E06_stats_word.py @@ -0,0 +1,36 @@ +def stats_test_en(s): + ''' + 封装统计英文单词词频的函数''' + i=s.split() + b=[] + d=',.*!-' + for e in i: + for f in d: + e=e.replace(f,'') + if len(e): + b.append(e) + g={} + b_set=set(b) + for h in b_set: + g[h]=b.count(h) + print(g) + print(sorted(g.items(),key=lambda x: x[1],reverse=True) +help(stats_test_en) + +def stats_test_cn(y) + ''' + 封装统计中文单词词频的函数''' + j=y.split() + c=[] + q=',。*!-' + for u in j: + for p in q: + k=k.replace(p,'') + if len(u): + c.append(u) + n={} + c_set=set(c) + for v in c_set: + k[v]=c.count(v) + print(k) + print(sorted(k.items(),key=lambda x: x[1],reverse=True) \ No newline at end of file diff --git a/exercises/1901100191/1001S05E05_array.py b/exercises/1901100191/1001S05E05_array.py new file mode 100644 index 000000000..1f1d49d49 --- /dev/null +++ b/exercises/1901100191/1001S05E05_array.py @@ -0,0 +1,14 @@ +a_list=[0,1,2,3,4,5,6,7,8,9] +a_list.sort(reverse=True) +print(a_list) +b=''.join(str(i) for i in a_list) +print(b) +c=b[2:8] +print(c) +d=c[::-1] +print(d) +int_value=int(d) +print(int_value) +print(bin(int_value)) +print(oct(int_value)) +print(hex(int_value)) \ No newline at end of file diff --git a/exercises/1901100191/1001S05E05_stats_text.py b/exercises/1901100191/1001S05E05_stats_text.py new file mode 100644 index 000000000..6b9fa2f2c --- /dev/null +++ b/exercises/1901100191/1001S05E05_stats_text.py @@ -0,0 +1,38 @@ +s=''' +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. 9 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!''' +i=s.split() +b=[] +d=',.*!-' +for e in i: + for f in d: + e=e.replace(f,'') + if len(e): + b.append(e) +print(b) +g={} +b_set=set(b) +for h in b_set: + g[h]=b.count(h) +print(g) +print(sorted(g.items(),key=lambda x: x[1],reverse=True)) \ No newline at end of file diff --git a/exercises/1901100191/1001S05E05_string.py b/exercises/1901100191/1001S05E05_string.py new file mode 100644 index 000000000..588e5e85c --- /dev/null +++ b/exercises/1901100191/1001S05E05_string.py @@ -0,0 +1,37 @@ +s=''' +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. 9 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!''' +print('better' in s) +print(s.replace('better','worse')) +b=s.replace('better','worse') +print(b.split()) +c=b.split() +d=[] +for e in c: + if e.find('ea')<0: + d.append(e) +print(d) +f=[g.swapcase()for g in d] +print(f) +f.sort() +print(f) \ No newline at end of file