Skip to content

Commit 9250971

Browse files
committed
new file: python_base/2_2.py
new file: python_base/2_3.py new file: python_base/2_4.py
1 parent 92d520a commit 9250971

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

python_base/2_2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#对URL进行分割
2+
# XXG 2012-10-23
3+
4+
url=raw_input("input the url:")
5+
if(url[0:4] == 'http'):
6+
domain=url[11:-4]
7+
elif(url[0:3] == 'www'):
8+
domain=url[4:-4]
9+
10+
print "Domain name :" + domain
11+
12+
#思考: 如:http://www.xxxx.edu.cn
13+
# https://xxx.cn /com.cn 怎么处理 split('.')

python_base/2_3.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#以正确的宽度在居中的盒子内打印一个句子
2+
3+
sentence = raw_input("Sentence:")
4+
5+
screen_width = 80
6+
text_width = len(sentence)
7+
box_width = text_width
8+
left_margin = (screen_width - box_width) // 2
9+
10+
11+
print
12+
print ' '*left_margin + '+' + '-' * box_width + '+'
13+
print ' '*left_margin + '|' + ' ' * text_width + '|'
14+
print ' '*left_margin + '|' + sentence + '|'
15+
print ' '*left_margin + '|' + ' ' * text_width + '|'
16+
print ' '*left_margin + '+' + '-' * box_width + '+'

python_base/2_4.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ÑéÖ¤Óû§ÃûºÍPINÂë
2+
3+
database = [
4+
['hello','1'],
5+
['world','2'],
6+
['!','3']
7+
]
8+
9+
username = raw_input("input the user name:")
10+
pin = raw_input("input tne user pin:")
11+
12+
if [username,pin] in database:
13+
print "Access greanted"
14+
else:
15+
print "Error pin code or username"
16+

0 commit comments

Comments
 (0)