Python答辩准备
PS: Python实验答辩流程
实验1:
-
分别使用列表与字典存储数据
-
展示两个打印结果
-
主要的技术要点为字典相关的遍历操作


实验2:
- 在实验1 的基础上,使用对应的增删改查操作
- 实验2 使用字典数组,查找通过遍历数组进行增删改查
- 使用数组的
append,remove方法直接增加 hero 字典 - 通过 hero 的 name 字段来进行查找 update 操作,直接使用字典的修改操作
- 使用数组的
- 实验2 ai 版在数据存储的操作与之前一样,但是在调用函数存在改善
- 将增删改查的操作用函数进行封装
add_hero,delete_hero,update_hero,search_hero,show_all- add_hero: 添加用户
- delete_hero: 删除第一个同名用户
- update_hero: 更新第一个同名用户的性别和职业字段
- search_hero: 打印第一个同名用户的信息
- show_all: 打印字典数组中的所有用户信息
实验3:
统计词组和单词,在此基础统计词频
主要的函数:
// 统计文本中的单词数和中文词语数
def count_words(text: str) -> dict:
// 统计词频,返回英文,中文,高频词
def word_frequency(text: str, top_n: int = 20) -> dict:
// 打印单词统计结果
def print_result(result: dict):
// 打印词频统计结果
def print_frequency(freq: dict):
// 读取用户粘贴的文本
def read_text_from_editor() -> str:
// 启动交互菜单
def run_interactive():
// 直接读取并统计指定文件
// 使用方法为:
// python char_count.py 文件名.txt
def run_file_mode(filepath: str):
使用的库及方法总结:
- re(正则表达式库)
- 核心用途 :提取英文单词
- 关键方法 :
- re.findall(r’\b[A-Za-z]+\b’, text) :匹配所有英文单词
- re.sub(r’\b[A-Za-z]+\b’, ‘’, text) :移除英文,避免干扰中文分词
- jieba.posseg(中文分词库)
- 核心用途 :中文分词与词性标注
- 关键方法 :
- pseg.cut(text_no_en) :对文本进行分词,返回包含词和词性的对象
- collections.Counter
- 核心用途 :词频统计
- 关键方法 :
- Counter(tokens) :创建词频计数器
- Counter.most_common(top_n) :获取 TopN 高频词
- sys(系统库)
- 用途 :命令行参数处理、程序退出
- 方法 : sys.argv 、 sys.exit()
- os(文件系统库)
- 用途 :文件路径验证
- 方法 : os.path.exists(filepath)
测试文本:
大学生活并不像很多人想象中那样轻松。面对课程、实验、考试和未来方向的压力,很多学生都会感到迷茫与疲惫。有时候,即使已经很努力了,也依然会因为效率不高、拖延或者缺乏动力而感到焦虑。但成长本来就是一个不断试错和调整的过程。真正重要的,不是一下子变得完美,而是在一次次失败后仍然愿意继续前进。只要能够保持一点点行动,比如认真完成今天的任务、坚持学习半小时、按时休息,就已经是在慢慢改变自己了。很多问题不会立刻得到答案,但时间和积累会让人逐渐找到属于自己的方向。
College life is not as easy as many people imagine. Facing pressure from courses, labs, exams, and future plans, many students feel confused and exhausted. Sometimes, even when people work very hard, they still become anxious because of low efficiency, procrastination, or a lack of motivation. However, growth is naturally a process of making mistakes and adjusting continuously. What truly matters is not becoming perfect overnight, but being willing to keep moving forward after repeated failures. As long as someone can maintain small actions, such as finishing today’s tasks seriously, studying for half an hour, or resting on time, they are already changing little by little. Many problems will not have immediate answers, but time and experience will gradually help people find their own direction.
实验4:
使用方法:
打开有郝物网站的步骤:
在lab4文件夹下打开powershell
终端输入: npm run dev
将网址复制粘贴到浏览器的搜索框: http://localhost:5177/
实验5:
文件结构
lab5/
├── app.py # Gradio Web 界面(主入口)
├── src/
│ ├── train.py # 模型训练脚本
│ ├── predict.py # 预测模块(加载模型 + 单条预测)
│ └── data_process.py # 数据处理(加载、清洗、划分)
├── models/
│ ├── sentiment_model.pkl # 训练好的逻辑回归模型
│ └── tfidf_vectorizer.pkl # 已拟合的 TF-IDF 向量化器
├── data/
│ └── comments_final.csv # 原始评论数据集
└── requirements.txt # 依赖清单