Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exercises/1901100290/1001S02E01_helloworld.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1001S02E01_helloworld.txt 

1 change: 1 addition & 0 deletions exercises/1901100290/1001S02E02_hello_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello world")
13 changes: 13 additions & 0 deletions exercises/1901100290/1001S02E03_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
a = float(input('Please enter a number: '))
option = input('Please enter a operator: ')
b = float(input('Please enter another number: '))
if option == '+':
print("result: ",a+b)
if option == '-':
print("result: ",a-b)
if option == '*':
print("result: ",a*b)
if option == '/':
print("result: ",a/b)


16 changes: 16 additions & 0 deletions exercises/1901100290/1001S02E04_control_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
for i in range(1, 10):
for j in range(1, i+1):
print('{}×{}={}'.format(j, i, i*j), end='\t')
print()

i = 1
while i < 10:
j = 1
while j<=i:
if i%2 == 0:
break
print('{}*{}={}'.format(i,j,i*j),end='\t')
j +=1
i +=1
print()

38 changes: 38 additions & 0 deletions exercises/1901100290/1001S02E05_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# 翻转

p=[0,1,2,3,4,5,6,7,8,9]
p.reverse()
print(p)


#翻转后的数组拼接成字符串串

y = ''.join(str(i) for i in p)


#⽤用字符串串切⽚片的⽅方式取出第三到第⼋八个字符(包含第三和第⼋八个字符)

a = y[2:8]


#将获得的字符串串进⾏行行翻转

c = a[::-1]


# 将结果转换为int类型

b = int(c)


# 分别转换成⼆二进制,⼋八进制,⼗十六进制

print('十进制整数为: ',b)
print('转换成二进制为: ',bin(b))
print('转换成八进制为: ',oct(b))
print('转换成十六进制为: ',hex(b))

int('b', 2)
int('b', 8)
int('b', 16)
46 changes: 46 additions & 0 deletions exercises/1901100290/1001S02E05_stats_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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!
'''






# 只统计英文单词,不包括非英文字符的其他任何符号,如连接符号、空白字符等等
list1 = text.split( )
i=0
for i in range(0,len(list1)):
list1[i]=list1[i].strip('*-,.!')
if list1[i]==' ':
list1[i].remove(' ')
else:
i=i+1
# 使用dict统计字符串样本中各个英文单词出现的次数
# 按照出现次数从大到小排列,示例 {'is': 10, ‘better’ : 9, …… }
import collections
print(collections.Counter(list1))




47 changes: 47 additions & 0 deletions exercises/1901100290/1001S02E05_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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!
'''

#1.将better替换为worse
s = text.replace('better','worse')
print(s)


#2.剔除含有ea的单词
a="EA"
b=[]
for a in s:
if a.find(s)<0:
b.append(a)
print(s)


#3.大小写替换
y=s.swapcase()
print(y)


#4.升序排列
list1=y.split()
list1.sort()
print(list1)
97 changes: 97 additions & 0 deletions exercises/1901100290/1001S02E06_stats_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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()#先将字符串根据空白字符分割成list,要调用str类型
words=[]#定义一个新的list型变量,存储处理过的单词
symbols=',.*-!'#针对文本筛选出需要剔除的非单词符号

for element in elements:
for symbol in symbols:#遍一遍需要剔除的符号
element=element.replace(symbol,'')#逐个替换字符号,用‘’是为了同时剔除符号所占的位置
if len(element):
words.append(element)#剔除了字符后如果element的长度不为0,则算作正常单词
print('',words)

counter = {}#初始化一个dict(字典)类型的变量,用来存放单词出现的次数
word_set = set(words)#set(集合)类型可以去掉列表里的重复元素
for word in word_set:
counter[word] = word.count(word)
print('',counter)#在for··in里减少循环次数
print('',sorted(counter.items(),key=lambda x:x[1],reverse=True))
#按照出现次数从大到小输出所有的单词及出现次数
#内置函数sorted的参数key表示按元素的哪一项进行排序
#dict类型counter的items方法会返回一个包含相应项(key,value)的元素列表
#print('counter.items()‘,counter.items())

sample_text = '''
The Zen of Python, by Tim Peters

美 丽 优 于 丑 陋.
直 言 优 于 暗 示.
简 单 优 于 复 杂.
复 杂 优 于 难 懂.
平 直 优 于 曲 折.
疏 散 优 于 密 集.
重 在 重 读.
打 破 规 则 的 特 别 不 能 称 之 为 特 别.
尽 管 练 习 会 打 败 纯 粹.
错 误 不 应 该 无 声 的 过 去.
除 非 明 晰 沉 默.
直 面 拒 绝 猜 测.
这 将 只 有 一 个-- 完 美 的 仅 有 的 --显 然 易 见 的 路 去 做.
尽 管 那 条 路 一 开 始 并 不 明 显 除 非 你 延 展.
现 在 好 过 从 不.
尽 管 从 不 常 好 过 *对 的* 现 在.
如 果 执 行 很 难 解 释,那 也 许 是 坏 点 子.
如 果 执 行 很 易 解 释,那 也 许 是 好 点 子.
命 名 空 间 是 最 棒 的 想 法 -- 让 我 们 做 的 更 多!
'''

elements=sample_text.split()#先将字符串根据空白字符分割成list,要调用str类型
words=[]#定义一个新的list型变量,存储处理过的单词
symbols=',.*-!'#针对文本筛选出需要剔除的非单词符号

for element in elements:
for symbol in symbols:#遍一遍需要剔除的符号
element=element.replace(symbol,'')#逐个替换字符号,用‘’是为了同时剔除符号所占的位置
if len(element):
words.append(element)#剔除了字符后如果element的长度不为0,则算作正常单词
print('',words)

counter = {}#初始化一个dict(字典)类型的变量,用来存放单词出现的次数
word_set = set(words)#set(集合)类型可以去掉列表里的重复元素
for word in word_set:
counter[word] = word.count(word)
print('',counter)#在for··in里减少循环次数
print('',sorted(counter.items(),key=lambda x:x[1],reverse=True))
#按照出现次数从大到小输出所有的单词及出现次数
#内置函数sorted的参数key表示按元素的哪一项进行排序
#dict类型counter的items方法会返回一个包含相应项(key,value)的元素列表
#print('counter.items()‘,counter.items())






6 changes: 6 additions & 0 deletions exercises/1901100290/README .md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 自学 Python 训练营



涅槃作业仓库
(https://github.com/selfteaching-learning-notes/selfteaching-learning-notes.github.io)