You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1004 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import os
import cppy.cp_util as util
# 工具函数
def extract_words(path_to_file):
return util.extract_words(path_to_file)
def frequencies(word_list):
return util.get_frequencies(word_list)
def sort(word_freq):
return util.sort_dict(word_freq)
def print_menu():
print("\n菜单选项:")
print("1. 上传并处理文件")
print("2. 继续")
print("3. 退出")
def open_and_print_file():
filename = input("请输入文件名:")
word_freqs = sort( frequencies(extract_words( filename )) )
util.print_word_freqs(word_freqs)
def main():
while True:
print_menu()
choice = input("请选择一个选项1/2/3")
if choice == '1':
open_and_print_file()
elif choice == '2':
continue
elif choice == '3':
print("退出程序。")
break
else:
print("无效的输入,请重新输入。")
if __name__ == "__main__":
main()