对于python3.x中的赋值,我必须创建一个程序来读取文本文件并输出字符、行、元音、大写字母、数字和单词的总数。用户必须提供文本文件的文件和路径。要文件很容易:
file = input("Please provide the file path and file name. \nFor example C:\\Users\\YourName\\Documents\\books\\book.txt \n:")
f = open(file, 'r')
text = f.read()
我试着使用一些简单的函数,比如:
^{pr2}$…但进一步阅读赋值会发现,我必须使用for
循环来分析字符串中的每个字符,然后使用多方向if
语句来检查它是否是元音、数字等
我知道我可以通过计算\n
的数目来计算行数,我也可以为wordsl使用.split()
函数,但我对如何去做相当茫然。在
我想把输出格式化成这样,虽然我想我可以在程序运行后解决这个问题。在
------------width=35---------|--width=8----
|number of characters : #####|
|number of lines : #####|
|number of vowels : #####|
|number of capital letters : #####|
|number of numeric digits : #####|
|number of words : #####|
如果有人能帮我上路并告诉我该怎么做,我将不胜感激。在
您可以使用NLTK工具箱(http://www.nltk.org/)来获取所需的信息。在
相关问题 更多 >
编程相关推荐