Skip to content

Commit 763273a

Browse files
author
Honlan
committed
first commit
1 parent 108f3e5 commit 763273a

62 files changed

Lines changed: 895 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
# Python-Basic
1+
## Python-Basic
2+
3+
Python基础入门课程,使用Python3.6自带的IDLE编程
4+
5+
介绍Python基础语法,包括变量、类型、条件、循环、列表、字符串、字典、函数等内容
6+
7+
## 文件说明
8+
9+
- `ppt`:课程课件,共14个pdf;
10+
- `codes`:课程代码,文件名带exercise表示课堂练习,不带表示课后习题;
11+
- `python-3.6.2-amd64.exe`:Windows下Python3.6安装文件;
12+
- `python-3.6.2-macosx10.6.pkg`:Mac下Python3.6安装文件。

codes/.DS_Store

6 KB
Binary file not shown.

codes/10_1_decrypt_message.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
alphabet = 'abcdefghijklmnopqrstuvwxyz'
2+
3+
key = int(input('> Please input the Key: '))
4+
msg = input('> Please input a message: ')
5+
msg = msg.lower()
6+
7+
new_msg = ''
8+
for c in msg:
9+
pos = alphabet.find(c)
10+
if pos == -1:
11+
new_msg += c
12+
else:
13+
pos = (pos + key) % len(alphabet)
14+
new_msg += alphabet[pos]
15+
16+
print('The encrypted message is: ', new_msg)
17+
18+
old_msg = ''
19+
for c in new_msg:
20+
pos = alphabet.find(c)
21+
if pos == -1:
22+
old_msg += c
23+
else:
24+
pos = (pos - key) % len(alphabet)
25+
old_msg += alphabet[pos]
26+
27+
print('The encrypted message is: ', old_msg)
28+

codes/10_2_decrypt_without_key.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
msg = "Kyv wLIKyvJK uzJKrEtv zE Kyv NFICu, zJ EFK svKNvvE Czwv rEu uvrKy. sLK NyvE z JKrEu zE wIFEK Fw PFL, PvK PFL uFE'K BEFN KyrK z CFMv PFL"
2+
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
3+
4+
for key in range(len(alphabet)):
5+
old_msg = ''
6+
for c in msg:
7+
pos = alphabet.find(c)
8+
if pos == -1:
9+
old_msg += c
10+
else:
11+
pos = (pos - key) % len(alphabet)
12+
old_msg += alphabet[pos]
13+
print('The Key: ', key)
14+
print('The decrypted message is: ', old_msg)

codes/10_find_and_remove.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
s1 = '今天天气非常非常的好'
2+
s2 = '非常的'
3+
4+
while True:
5+
pos = s1.find(s2)
6+
if pos == -1:
7+
break
8+
9+
s_before = s1[:pos]
10+
s_after = s1[pos + len(s2):]
11+
s1 = s_before + s_after
12+
print(s1)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import random
2+
3+
alphabet = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'
4+
5+
base = alphabet.split(',')
6+
target = base.copy()
7+
random.shuffle(target)
8+
9+
cipher = {}
10+
d_cipher = {}
11+
for i in range(len(base)):
12+
cipher[base[i]] = target[i]
13+
d_cipher[target[i]] = base[i]
14+
# d_cipher = {v: k for k, v in cipher.items()}
15+
16+
msg = input('Please input a message: ')
17+
new_msg = ''
18+
for c in msg:
19+
new_msg = new_msg + cipher.get(c, c)
20+
print('The secret message is: ', new_msg)
21+
22+
plain_msg = ''
23+
for c in new_msg:
24+
plain_msg = plain_msg + d_cipher.get(c, c)
25+
26+
print('The plain message is: ', plain_msg)
27+
28+
29+
30+

codes/11_exercise_count_numbers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
numbers = input('Please input a lots of numbers: ')
2+
count1 = {}
3+
count2 = {}
4+
count2['oushu'] = 0
5+
count2['jishu'] = 0
6+
7+
for c in numbers:
8+
if c in count1:
9+
count1[c] += 1
10+
else:
11+
count1[c] = 1
12+
13+
if int(c) % 2 == 0:
14+
count2['oushu'] += 1
15+
else:
16+
count2['jishu'] += 1
17+
18+
print(count1)
19+
print(count2)
20+

codes/12_1_rect_function.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def rect_cal(width, height):
2+
area = width * height
3+
zhouchang = (width + height) * 2
4+
return area, zhouchang
5+
6+
width = float(input('Please input the width: '))
7+
height = float(input('Please input the height: '))
8+
9+
print(rect_cal(width, height))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def find_and_remove(s1, s2, flag):
2+
pos = s1.find(s2)
3+
if pos == -1:
4+
return s1
5+
6+
if flag:
7+
# 全部删除
8+
while True:
9+
pos = s1.find(s2)
10+
if pos == -1:
11+
break
12+
s1 = s1[:pos] + s1[pos + len(s2):]
13+
return s1
14+
else:
15+
# 只删一次
16+
return s1[:pos] + s1[pos + len(s2):]
17+
18+
print(find_and_remove('你好啊你好啊', '我不好', True))
19+
print(find_and_remove('今天天气非常非常非常的好', '非常', False))
20+
print(find_and_remove('今天天气非常非常非常的好', '非常', True))
21+
print('=' * 10)
22+
print('今天天气非常非常非常的好'.replace('非常', ''))
23+
print('今天天气非常非常非常的好'.replace('非常', '', 1))
24+
25+
26+
27+
28+
29+
30+

0 commit comments

Comments
 (0)