Skip to content

Commit 787294c

Browse files
committed
complete 0004
1 parent fe26360 commit 787294c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Jimmy66/0004/0004.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
#导入模块,进行正则匹配
5+
import re
6+
7+
#计算单词个数
8+
def counter(string):
9+
words = re.findall(r'[a-zA-Z]+\b',string)
10+
amount = len(words)
11+
return str(amount)
12+
13+
#从文件中读取数据
14+
def file_read(filename):
15+
with open(filename,'r') as fp:
16+
article = fp.read()
17+
return article
18+
19+
#主函数
20+
if __name__ == '__main__':
21+
string = file_read('GitHub.txt')
22+
result = counter(string)
23+
print 'There are', result, 'words in this article.'
24+
print "这篇文章中有" + result + "个英文单词"
25+
26+
27+

Jimmy66/0004/GitHub.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
GitHub
2+
3+
From Wikipedia, the free encyclopedia
4+
5+
GitHub is a web-based Git repository hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features. Unlike Git, which is strictly a command-line tool, GitHub provides a web-based graphical interface and desktop as well as mobile integration. It also provides access control and several collaboration features such as wikis, task management, and bug tracking and feature requests for every project.[2]
6+
7+
GitHub offers both paid plans for private repositories and free accounts, which are usually used to host open-source software projects. As of 2014, GitHub reports having over 3.4 million users and with 16.7 million repositories[3] making it the largest code host in the world.[4]
8+

0 commit comments

Comments
 (0)