diff --git a/exercises/190110304/1001S02E02_hello_python.py b/exercises/190110304/1001S02E02_hello_python.py index e75154b7c..5a68b6a56 100644 --- a/exercises/190110304/1001S02E02_hello_python.py +++ b/exercises/190110304/1001S02E02_hello_python.py @@ -1 +1,12 @@ -print("hello world") \ No newline at end of file + +i = 1 +while i < 10: + j = 1 + while j < i + 1: + if i%2 == 0: + break + print(j, '*', i, '=', i * j, sep='', end='\t') + j += 1 + + print() + diff --git a/exercises/190110304/1001S02E05_array.py b/exercises/190110304/1001S02E05_array.py new file mode 100644 index 000000000..8001d59d9 --- /dev/null +++ b/exercises/190110304/1001S02E05_array.py @@ -0,0 +1,19 @@ +a=[0,1, 2, 3, 4, 5, 6, 7, 8, 9] +a=a[::-1]#将数组反转 +print(a) +str = ''.join(str(i) for i in a) #将数组转换成字串符 +print(str) + +b=str[2:8] #⽤字符串切⽚的⽅式取出第三到第⼋个字符 +print(b) + +b=b[::-1]#将取出的结果反转 +print(b) + +c=int(b)#将结果转换为 int 类型 +print(c) + +#分别转换成⼆二进制,⼋八进制,⼗十六进制,最后输出三种进制的结果 +print('二进制:',bin(c)) +print('八进制:',oct(c)) +print('十六进制:',hex(c)) diff --git a/exercises/190110304/1001S02E05_stats_text.py b/exercises/190110304/1001S02E05_stats_text.py new file mode 100644 index 000000000..2c9e805d8 --- /dev/null +++ b/exercises/190110304/1001S02E05_stats_text.py @@ -0,0 +1,32 @@ + +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!''') +text1=text.split()#将字符串转换成列表 +text2={} #创建字典 +for i in text1: #for是发起循环的关键词;i in text1是循环规则,i是依次得到txet1列表中的各个值,然后按照索引顺序循环下去,直到最后一个 + if i in text2: + text2[i]=text2[i]+1 #统计单词出现的次数 + else: + text2[i]=1 +print(text2) + diff --git a/exercises/190110304/1001S02E05_string.py b/exercises/190110304/1001S02E05_string.py new file mode 100644 index 000000000..e56ff1afa --- /dev/null +++ b/exercises/190110304/1001S02E05_string.py @@ -0,0 +1,50 @@ +import re # 正则表达式 +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!''') + + +text2=text.replace("better","worse") #用replace将文本中 better 全部替换成 worse +print (text2) + +text3=text.split() #split将字符串转换成列表 +print (text3) + +text4 = [] + +for i in text3: #for是发起循环的关键词;i in text3是循环规则,i是依次得到txet3列表中的各个值,然后按照索引顺序循环下去,直到最后一个 + if i.find("ea") < 0: #这个if语句是判断“ea"是不是在某个单词里面 + text4.append(i) + print (text4) + +text5=text.swapcase()#用swapcase将文本中的大小写字母进行互换 +print(text5) + +text6=text3.sort() #先用split将字符串改成列表形式 然后再用sort进行排序 这里用text3是因为 text3是已经转变完成的列表 +print(text3) + + + + + + + +