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 1901100207/1001S02E02_hello_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('hello world')
19 changes: 19 additions & 0 deletions 1901100207/1001S02E03_calculator.py
Original file line number Diff line number Diff line change
@@ -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('无效的运算符')
18 changes: 18 additions & 0 deletions 1901100207/1001S02E04_control_flow.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions 1901100207/1001S02E05_array.py
Original file line number Diff line number Diff line change
@@ -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))
40 changes: 40 additions & 0 deletions 1901100207/1001S02E05_stats_text.py
Original file line number Diff line number Diff line change
@@ -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))
38 changes: 38 additions & 0 deletions 1901100207/1001S02E05_string.py
Original file line number Diff line number Diff line change
@@ -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))