25级第三次实验报告
| 序号 | 学号(按自己在班里的顺序填) | 完成(完成填1) |
| 1 | 2025010089 | 1 |
| 2 | 2025010090 | 1 |
| 3 | 2025010091 | 1 |
| 4 | 2025010092 | 1 |
| 5 | 2025010093 | 1 |
| 6 | 2025010094 | 1 |
| 7 | 2025010095 | 1 |
| 8 | 2025010096 | 1 |
| 9 | 2025010097 | 1 |
| 10 | 2025010098 | 1 |
| 11 | 2025010099 | 1 |
| 12 | 2025010100 | 1 |
| 13 | 2025010101 | 1 |
| 14 | 2025010102 | 1 |
| 15 | 2025010103 | 1 |
| 16 | 2025010104 | 1 |
| 17 | ||
| 18 | 2025010106 |
2
|
| 19 | 2025010107 | 1 |
| 20 | ||
| 21 | 2025010109 | 1 |
| 22 | ||
| 23 | 2025010112 | 1 |
| 24 | 2025010113 | 1 |
| 25 | 2025010114 | 1 |
| 26 | 2025010115 | 1 |
| 27 | 2025010117 | 1 |
| 28 | 2025010118 | 1 |
| 29 | 2025010119 | 1 |
| 30 | 2025010120 | 1 |
| 31 | 2025010121 | 1 |
| 32 | 2025010122 | 1 |
| 33 | ||
| 34 | 2025010124 | 1 |
| 35 | 2025010125 | 1 |
| 36 | ||
| 37 | 2025010127 | 1 |
| 38 | 2025010128 | 1 |
| 39 | 2025010130 | 1 |
| 40 | 2025010131 | 1 |
| 41 | 2025010132 | 1 |
2025010089张静文
通讯录查增删
contacts = {} while True: print("\n1 添加 2 删除 3 查询 0 退出") c = input("请选:") if c == "1": name = input("姓名:") phone = input("电话:") contacts[name] = phone print("添加成功") elif c == "2": name = input("输入要删除的姓名:") if name in contacts: del contacts[name] print("已删除") else: print("不存在") elif c == "3": name = input("输入要查询的姓名:") print(contacts.get(name, "不存在")) elif c == "0": break
2025010090殷慧湘
#输入
y=int(input("输入年份"))
m=int(input("输入月份"))
d=int(input("输入日期"))
def day_of_year(year,month,day):
month_days=[31,28,31,30,31,30,31,31,30,31,30,31]
if ( year % 4 == 0 and year % 100 != 0) or (year %400 == 0):
month_days =[31,29,31,30,31,30,31,31,30,31,30,31]
total = sum(month_days[:month-1])+day
return total
print(f"这是{y}年的第{day_of_year(y,m,d)}天")


2025010091张译心
筛选平均成绩高于所在班的人
# 自编两个班级成绩 # 格式:[姓名, 班级, 成绩] scores = [ ["小明", 1, 88], ["小红", 1, 76], ["小刚", 1, 92], ["小丽", 1, 69], ["小华", 1, 85], ["小亮", 2, 79], ["小燕", 2, 95], ["小磊", 2, 68], ["小琪", 2, 82], ["小航", 2, 73] ] # 1. 计算每个班总分、人数、平均分 class1 = [] class2 = [] for name, cls, score in scores: if cls == 1: class1.append(score) else: class2.append(score) # 求各班平均分 avg1 = sum(class1) / len(class1) avg2 = sum(class2) / len(class2) print(f"1班平均分:{avg1:.2f}") print(f"2班平均分:{avg2:.2f}") print("-" * 40) # 2. 筛选大于本班平均分的同学 print("高于所在班级平均分的同学:") for name, cls, score in scores: if cls == 1: if score > avg1: print(f"姓名:{name},班级:{cls},成绩:{score}") else: if score > avg2: print(f"姓名:{name},班级:{cls},成绩:{score}")

2025010092朱翔鸽
计算院总人数
import csv # ====================== 第一步:自动创建两个表格 ====================== # 1. 创建【院系表.csv】 depts = ["计算机学院", "文学院", "外国语学院", "数统学院", "医学院"] with open("院系表.csv", "w", newline="", encoding="utf-8") as f: writer = csv.writer(f) writer.writerow(["院系"]) for d in depts: writer.writerow([d]) # 2. 创建【学生表.csv】,三列:姓名、学号、所在系 students = [ ["张三", "2025001", "计算机学院"], ["李四", "2025002", "文学院"], ["王五", "2025003", "计算机学院"], ["赵六", "2025004", "外国语学院"], ["钱七", "2025005", "数统学院"], ["孙八", "2025006", "文学院"], ["周九", "2025007", "医学院"], ["吴十", "2025008", "计算机学院"], ] with open("学生表.csv", "w", newline="", encoding="utf-8") as f: writer = csv.writer(f) writer.writerow(["姓名", "学号", "所在系"]) writer.writerows(students) # ====================== 第二步:统计各院系总人数 ====================== dept_count = {} # 读取学生表 with open("学生表.csv", "r", encoding="utf-8") as f: reader = csv.DictReader(f) for row in reader: xi = row["所在系"].strip() dept_count[xi] = dept_count.get(xi, 0) + 1 # 读取院系表,输出每个院系人数 print("===== 各院系总人数 =====") with open("院系表.csv", "r", encoding="utf-8") as f: reader = csv.DictReader(f) for row in reader: d = row["院系"].strip() print(f"{d}:{dept_count.get(d, 0)} 人")


2025010093惠盾
查找科室
# 安康学院 行政后勤科室查询系统(无二级学院) def init_ankang_dept(): """安康学院行政、职能、后勤、教辅科室""" data = { "党政职能部门": [ "党委办公室", "校长办公室", "党委组织部", "党委宣传部", "人事处", "财务处", "教务处", "学生工作处", "招生就业处", "科学技术处", "国有资产管理处", "保卫处", "离退休工作处", "审计处", "工会","团委" ], "教辅服务单位": [ "图书馆", "网络信息中心", "学报编辑部", "教师发展中心", "实验实训管理中心" ], "后勤基建服务": [ "后勤管理处", "基建处", "校医院", "宿舍管理科", "食堂管理中心", "校园维修科" ] } return data def search(keyword, dept_dict): """模糊关键词查询""" result = {} kw = keyword.strip().lower() for type_name, depts in dept_dict.items(): match = [d for d in depts if kw in d.lower()] if match: result[type_name] = match return result def show_all(dept_dict): """展示全部科室""" print("\n===== 安康学院行政及后勤全部科室 =====") for cate, dept_list in dept_dict.items(): print(f"\n【{cate}】") for i, d in enumerate(dept_list, 1): print(f"{i}. {d}") def main(): dept_data = init_ankang_dept() print("=" * 45) print(" 安康学院科室信息查询系统") print("=" * 45) print("指令:all 查看全部 | exit 退出程序") while True: inp = input("\n请输入查询关键词:") if inp.lower() == "exit": print("退出查询,再见!") break elif inp.lower() == "all": show_all(dept_data) else: res = search(inp, dept_data) if res: print(f"\n🔍 搜索【{inp}】结果:") for c, ds in res.items(): print(f"\n▶ {c}") for d in ds: print(f" · {d}") else: print("未查询到相关科室") if __name__ == "__main__": main()

2025010094谢润泽
import cv2 import tkinter as tk from tkinter import filedialog, ttk from PIL import Image, ImageTk import threading import time class VideoPlayer: def __init__(self, root): self.root = root self.root.title("简易视频播放器") self.root.geometry("800x600") # 视频相关变量 self.cap = None self.is_playing = False self.is_pause = False self.frame_rate = 30 self.video_path = "" # 界面布局 self.create_widgets() # 定时刷新画面 self.update_frame() def create_widgets(self): # 视频显示区域 self.video_label = ttk.Label(self.root) self.video_label.pack(fill=tk.BOTH, expand=True, padx=10, pady=10) # 按钮区域 btn_frame = ttk.Frame(self.root) btn_frame.pack(pady=5) self.btn_open = ttk.Button(btn_frame, text="打开视频", command=self.open_video) self.btn_open.grid(row=0, column=0, padx=5) self.btn_play = ttk.Button(btn_frame, text="播放", command=self.play_video) self.btn_play.grid(row=0, column=1, padx=5) self.btn_pause = ttk.Button(btn_frame, text="暂停", command=self.pause_video) self.btn_pause.grid(row=0, column=2, padx=5) self.btn_stop = ttk.Button(btn_frame, text="停止", command=self.stop_video) self.btn_stop.grid(row=0, column=3, padx=5) def open_video(self): """打开本地视频文件""" self.stop_video() file_path = filedialog.askopenfilename( title="选择视频文件", filetypes=[("视频文件", "*.mp4 *.avi *.mov *.mkv"), ("所有文件", "*.*")] ) if not file_path: return self.video_path = file_path self.cap = cv2.VideoCapture(file_path) self.frame_rate = int(self.cap.get(cv2.CAP_PROP_FPS)) def play_video(self): """播放视频""" if self.cap is None: self.open_video() if not self.is_playing: self.is_playing = True self.is_pause = False # 子线程播放,避免界面卡顿 threading.Thread(target=self.play_loop, daemon=True).start() elif self.is_pause: self.is_pause = False def pause_video(self): """暂停视频""" if self.is_playing: self.is_pause = True def stop_video(self): """停止视频,重置状态""" self.is_playing = False self.is_pause = False if self.cap is not None: self.cap.release() self.cap = None # 清空画面 self.video_label.config(image="") def play_loop(self): """视频播放循环(子线程)""" while self.is_playing and self.cap.isOpened(): if self.is_pause: time.sleep(0.1) continue ret, frame = self.cap.read() if not ret: # 视频播放完毕,自动停止 self.stop_video() break # OpenCV图像转RGB + 缩放适配窗口 frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) img = Image.fromarray(frame) # 自适应缩放 win_w, win_h = self.video_label.winfo_width(), self.video_label.winfo_height() if win_w > 10 and win_h > 10: img = img.resize((win_w, win_h), Image.Resampling.LANCZOS) # 更新界面 self.tk_img = ImageTk.PhotoImage(image=img) self.video_label.config(image=self.tk_img) # 控制帧率 time.sleep(1 / self.frame_rate) def update_frame(self): self.root.after(10, self.update_frame) if __name__ == "__main__": root = tk.Tk() app = VideoPlayer(root) root.mainloop()
2025010095徐雨轩
加载游戏地图
import turtle import sys # 游戏地图(和书上的7x7地图一致) # 1=墙, 0=空地, 2=箱子, 3=目标点, 4=玩家 map_data = [ [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 4, 0, 0, 1], [1, 0, 2, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0, 1], [1, 0, 0, 2, 0, 0, 1], [1, 0, 3, 0, 3, 0, 1], [1, 1, 1, 1, 1, 1, 1] ] CELL_SIZE = 60 # 每个格子的大小 MAP_WIDTH = len(map_data[0]) MAP_HEIGHT = len(map_data) # 初始化海龟绘图 screen = turtle.Screen() screen.title("推箱子游戏(无依赖版)") screen.setup(width=MAP_WIDTH * CELL_SIZE, height=MAP_HEIGHT * CELL_SIZE) screen.tracer(0) # 关闭自动刷新,手动更新画面 # 定义画笔 pen = turtle.Turtle() pen.speed(0) pen.hideturtle() pen.penup() # 游戏元素位置 player = None boxes = [] targets = [] walls = [] # 解析地图 def parse_map(): global player, boxes, targets, walls player = None boxes.clear() targets.clear() walls.clear() for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): cell = map_data[y][x] if cell == 1: walls.append((x, y)) elif cell == 2: boxes.append((x, y)) elif cell == 3: targets.append((x, y)) elif cell == 4: player = (x, y) # 绘制单个格子 def draw_cell(x, y, color): pen.goto(x * CELL_SIZE - MAP_WIDTH * CELL_SIZE / 2, -y * CELL_SIZE + MAP_HEIGHT * CELL_SIZE / 2) pen.color(color) pen.begin_fill() for _ in range(4): pen.forward(CELL_SIZE) pen.right(90) pen.end_fill() pen.color("black") pen.pendown() for _ in range(4): pen.forward(CELL_SIZE) pen.right(90) pen.penup() # 绘制整个游戏界面 def draw_game(): screen.clear() screen.tracer(0) pen.clear() # 绘制背景 for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): draw_cell(x, y, "white") # 绘制墙 for (x, y) in walls: draw_cell(x, y, "gray") # 绘制目标点(绿色圆圈) pen.color("green") for (x, y) in targets: pen.goto(x * CELL_SIZE - MAP_WIDTH * CELL_SIZE / 2 + CELL_SIZE / 2, -y * CELL_SIZE + MAP_HEIGHT * CELL_SIZE / 2 + CELL_SIZE / 2) pen.dot(CELL_SIZE // 3 * 2, "green") # 绘制箱子 for (x, y) in boxes: if (x, y) in targets: draw_cell(x, y, "blue") else: draw_cell(x, y, "red") # 绘制玩家(黑色圆圈) pen.color("black") pen.goto(player[0] * CELL_SIZE - MAP_WIDTH * CELL_SIZE / 2 + CELL_SIZE / 2, -player[1] * CELL_SIZE + MAP_HEIGHT * CELL_SIZE / 2 + CELL_SIZE / 2) pen.dot(CELL_SIZE // 3 * 2, "black") screen.update() # 玩家移动逻辑 def move(dx, dy): global player, boxes new_x = player[0] + dx new_y = player[1] + dy # 撞墙判断 if (new_x, new_y) in walls: return # 推箱子判断 if (new_x, new_y) in boxes: box_new_x = new_x + dx box_new_y = new_y + dy # 箱子不能推到墙或其他箱子上 if (box_new_x, box_new_y) in walls or (box_new_x, box_new_y) in boxes: return # 更新箱子位置 boxes.remove((new_x, new_y)) boxes.append((box_new_x, box_new_y)) # 更新玩家位置 player = (new_x, new_y) draw_game() check_win() # 检查是否通关 def check_win(): for box in boxes: if box not in targets: return # 通关提示 pen.goto(0, 0) pen.color("black") pen.write("🎉 恭喜通关!按R键重置游戏", align="center", font=("Arial", 16, "bold")) screen.update() # 重置游戏 def reset_game(): parse_map() draw_game() # 键盘控制绑定 screen.listen() screen.onkey(lambda: move(0, -1), "Up") screen.onkey(lambda: move(0, 1), "Down") screen.onkey(lambda: move(-1, 0), "Left") screen.onkey(lambda: move(1, 0), "Right") screen.onkey(reset_game, "r") screen.onkey(sys.exit, "Escape") # 按ESC退出 # 初始化游戏 parse_map() draw_game() # 保持窗口运行 turtle.done()


2025010096刘加鑫
聊天窗口



import tkinter as tk from tkinter import scrolledtext # 主窗口 root = tk.Tk() root.title("简易聊天窗口") root.geometry("550x500") root.resizable(False, False) # 聊天显示区域 chat_text = scrolledtext.ScrolledText(root, width=65, height=25, font=("微软雅黑", 10)) chat_text.place(x=10, y=10) chat_text.config(state=tk.DISABLED) # 输入框 input_entry = tk.Entry(root, width=50, font=("微软雅黑", 11)) input_entry.place(x=15, y=430, height=35) # 发送消息函数 def send_msg(): msg = input_entry.get().strip() if not msg: return # 解锁写入消息 chat_text.config(state=tk.NORMAL) chat_text.insert(tk.END, f"我:{msg}\n") chat_text.config(state=tk.DISABLED) chat_text.see(tk.END) input_entry.delete(0, tk.END) # 自动回复 auto_reply = ["哈哈", "收到", "好的", "嗯嗯", "在呢"] import random reply = random.choice(auto_reply) chat_text.config(state=tk.NORMAL) chat_text.insert(tk.END, f"对方:{reply}\n") chat_text.config(state=tk.DISABLED) chat_text.see(tk.END) # 发送按钮 send_btn = tk.Button(root, text="发送", command=send_msg, width=8, height=2, bg="#409EFF", fg="white") send_btn.place(x=450, y=430) # 回车发送 root.bind("<Return>", lambda e: send_msg()) root.mainloop()
2025010097马浩
窗口 计算器
from tkinter import * # 创建主窗口 root = Tk() root.geometry('200x200+280+280') # 修正全角×为半角x root.title('计算器示例') # 用于显示输入内容的变量 display_var = StringVar() display_var.set("") # 显示框(可选,增强体验) display = Entry(root, textvariable=display_var, font=('Arial', 16), justify='right') display.grid(row=0, column=0, columnspan=3, padx=5, pady=5) # 按钮点击事件函数 def button_click(value): current = display_var.get() display_var.set(current + str(value)) # 创建按钮 L1 = Button(root, text='1', width=5, bg='yellow', command=lambda: button_click('1')) L2 = Button(root, text='2', width=5, command=lambda: button_click('2')) L3 = Button(root, text='3', width=5, command=lambda: button_click('3')) L4 = Button(root, text='4', width=5, command=lambda: button_click('4')) L5 = Button(root, text='5', width=5, bg='green', command=lambda: button_click('5')) L6 = Button(root, text='6', width=5, command=lambda: button_click('6')) L7 = Button(root, text='7', width=5, command=lambda: button_click('7')) L8 = Button(root, text='8', width=5, command=lambda: button_click('8')) L9 = Button(root, text='9', width=5, bg='yellow', command=lambda: button_click('9')) L0 = Button(root, text='0', width=12, command=lambda: button_click('0')) # 调整宽度适配跨列 Lp = Button(root, text='.', width=5, command=lambda: button_click('.')) # grid布局(注意:原代码的row序号可根据实际显示框调整) L1.grid(row=1, column=0) L2.grid(row=1, column=1) L3.grid(row=1, column=2) L4.grid(row=2, column=0) L5.grid(row=2, column=1) L6.grid(row=2, column=2) L7.grid(row=3, column=0) L8.grid(row=3, column=1) L9.grid(row=3, column=2) L0.grid(row=4, column=0, columnspan=2, sticky=E+W) # 0键跨两列 Lp.grid(row=4, column=2, sticky=E+W) # 主循环 root.mainloop()

2025010098韩晓媛
窗口图
import tkinter#导入Tkinter模块 win=tkinter.Tk()#创建Windows窗口对象 win.title("画圆窗口") # 设置窗口标题 win.geometry("300x250")#设置窗口大小 canvas=tkinter.Canvas(win, bg="white", width=300, height=250)#创建画布组件,Canvas:画布控件,显示图形元素,例如线条或文本 canvas.pack() # pack几何布局管理,把画布放在窗口里显示出来 canvas.create_oval(75, 75, 225, 225, fill="yellow", outline="black")#画圆,(75,75)左上角,(225,225)右下角 win.mainloop()#启动窗口消息循环

2025010099张嘉诚
键盘控制人物移动
import pygame
# 初始化Pygame
pygame.init()
# 窗口尺寸与创建窗口
WIDTH = 800
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("键盘控制人物移动")
# 人物基础参数
player_x = WIDTH // 2 # 初始X坐标
player_y = HEIGHT // 2 # 初始Y坐标
player_width = 50 # 人物宽度
player_height = 70 # 人物高度
move_speed = 5 # 移动速度
# 控制帧率
clock = pygame.time.Clock()
running = True
# 主循环
while running:
clock.tick(60) # 固定60帧
# 监听窗口关闭事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# 键盘按键检测,控制移动+边界限制
key_list = pygame.key.get_pressed()
# 左移
if key_list[pygame.K_LEFT] and player_x > 0:
player_x -= move_speed
# 右移
if key_list[pygame.K_RIGHT] and player_x < WIDTH - player_width:
player_x += move_speed
# 上移
if key_list[pygame.K_UP] and player_y > 0:
player_y -= move_speed
# 下移
if key_list[pygame.K_DOWN] and player_y < HEIGHT - player_height:
player_y += move_speed
# 填充背景色(浅灰色)
screen.fill((240, 240, 240))
# 绘制简易人物:圆形头部 + 矩形身体
# 头部:黄色圆形
pygame.draw.circle(screen, (255, 200, 0), (player_x + 25, player_y + 15), 15)
# 身体:蓝色矩形
pygame.draw.rect(screen, (30, 144, 255), (player_x + 10, player_y + 30, 30, 40))
# 更新画面
pygame.display.flip()
# 退出程序
pygame.quit()

2025010100霍延萌
价格
# 商品列表(名称: 单价)
goods = {
"苹果": 5,
"香蕉": 3,
"橙子": 4,
"牛奶": 6,
"面包": 8
}
# 选购列表(名称: 数量)
cart = {
"苹果": 2,
"香蕉": 5,
"牛奶": 1
}
# 计算并打印明细和总价
total = 0
print("🛒 购物结算")
print("=" * 20)
for item, count in cart.items():
if item in goods:
subtotal = goods[item] * count
total += subtotal
print(f"{item}:{goods[item]}元 × {count} = {subtotal}元")
print("=" * 20)
print(f"💰 总计:{total}元")

2025010101袁泉
矢量的点乘与叉乘
def cross_product(v1, v2): """ 计算两个3D矢量的叉乘(外积) :param v1: 矢量1(列表/元组,长度为3) :param v2: 矢量2(列表/元组,长度为3) :return: 叉乘结果(3D矢量列表) """ if len(v1) != 3 or len(v2) != 3: raise ValueError("叉乘仅支持3D矢量!") x = v1[1] * v2[2] - v1[2] * v2[1] y = v1[2] * v2[0] - v1[0] * v2[2] z = v1[0] * v2[1] - v1[1] * v2[0] return [x, y, z] def dot_product(v1, v2): """ 计算两个矢量的点乘(内积) :param v1: 矢量1(列表/元组) :param v2: 矢量2(列表/元组) :return: 点乘结果(标量) """ if len(v1) != len(v2): raise ValueError("两个矢量的维度必须相同!") return sum(a * b for a, b in zip(v1, v2)) # 1. 定义两个矢量 v1 = [1, 2, 3] v2 = [4, 5, 6] # 2. 调用叉乘函数 cross_result = cross_product(v1, v2) print("叉乘结果:", cross_result) # 3. 调用点乘函数 dot_result = dot_product(v1, v2) print("点乘结果:", dot_result)

2025010102沈玉婷
日期加减函数
# 2026年是平年,每月天数 md = [31,28,31,30,31,30,31,31,30,31,30,31] # 1. 日期 → 当年第几天(只处理2026年) def riqi_days(m, d): total = 0 # 累加前面月份的天数 for i in range(m-1): total += md[i] # 加上当月的天数 total += d return total # 2. 当年第几天 → 日期(只处理2026年) def days_riqi(n): m = 0 while True: day = md[m] if n > day: n -= day m += 1 else: break return m+1, n # 2026年5月1日 m1, d1 = 5, 1 # 1. 转成当年的第几天 t1 = riqi_days(m1, d1) print("2026年5月1日 是2026年的第", t1, "天") # 2. 日期 + 天数:加3天 jia = t1 + 3 nm, nd = days_riqi(jia) print("2026年5月1日加3天:", "2026年", nm, "月", nd, "日") # 3. 日期 - 天数:减2天 jian = t1 - 2 nm2, nd2 = days_riqi(jian) print("2026年5月1日减2天:", "2026年", nm2, "月", nd2, "日") # 4. 日期 - 日期:求相差天数(今年内) m2, d2 = 5, 10 t2 = riqi_days(m2, d2) cha = t2 - t1 print("2026年5月1日和5月10日相差:", cha, "天")

2025010103黄俊
创建一个通讯录的1字典
# 通讯录字典 txl = {} while True: print("\n1增加 2修改 3删除 4排序 0退出") n = input("请输入编号:") # 1 增加 if n == "1": name = input("姓名:") phone = input("电话:") txl[name] = phone # 2 修改 elif n == "2": name = input("要修改的姓名:") if name in txl: txl[name] = input("新电话:") # 3 删除 elif n == "3": name = input("要删除的姓名:") if name in txl: del txl[name] # 4 排序 elif n == "4": print("===排序后===") for k,v in sorted(txl.items()): print(k, v) # 0 退出 elif n == "0": print("退出") break

2025010104许乐乐
日期加减函数的计算
from datetime import datetime, timedelta # 定义日期加减函数 def date_calc(nian, yue, ri, tian_shu): # 把输入的年月日转成日期对象 start_date = datetime(nian, yue, ri) # 进行天数加减:正数加天数,负数减天数 end_date = start_date + timedelta(days = tian_shu) # 返回计算后的 年 月 日 return end_date.year, end_date.month, end_date.day # ---------- 交互式输入 自己随便改 ---------- # 1.手动输入原日期 y = int(input("请输入年份:")) m = int(input("请输入月份:")) d = int(input("请输入日期:")) # 2.输入要加减的天数 num = int(input("请输入要加减的天数(正数加、负数减):")) # 3.调用函数计算 new_y, new_m, new_d = date_calc(y, m, d, num) # 4.输出结果 print(f"\n计算后的日期:{new_y}年{new_m}月{new_d}日")

2025010107孙瑞妍
将excel内容转化为列表
import pandas as pd df = pd.read_excel("test.xlsx", engine="openpyxl") data_list = df.values.tolist() print(data_list)

2025010106 钟海洋 角度计算

2025010108叱干育


2025010109 黄帅豪
推箱子
import tkinter as tk # 定义地图(1墙 2玩家 3箱子 4目标) level = [ [1, 1, 1, 1, 1, 1, 1], [1, 2, 0, 0, 0, 0, 1], [1, 0, 3, 0, 4, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 3, 0, 4, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1] ] cell_size = 60 # 格子大小(像素) colors = { 0: 'white', # 空地 1: 'gray', # 墙壁 2: 'blue', # 玩家 3: 'brown', # 箱子 4: 'yellow' # 目标点背景 } root = tk.Tk() root.title("推箱子 - 静态展示") rows = len(level) cols = len(level[0]) canvas = tk.Canvas(root, width=cols * cell_size, height=rows * cell_size) canvas.pack() # 绘制静态画面 for i in range(rows): for j in range(cols): x1 = j * cell_size y1 = i * cell_size x2 = x1 + cell_size y2 = y1 + cell_size val = level[i][j] # 绘制背景 if val == 4: # 目标点背景色为黄色 canvas.create_rectangle(x1, y1, x2, y2, fill=colors[4], outline='black') else: canvas.create_rectangle(x1, y1, x2, y2, fill=colors[val], outline='black') # 绘制特殊物体(覆盖在背景上) if val == 2: # 玩家 canvas.create_oval(x1 + 10, y1 + 10, x2 - 10, y2 - 10, fill='blue') elif val == 3: # 箱子 canvas.create_rectangle(x1 + 10, y1 + 10, x2 - 10, y2 - 10, fill='brown') elif val == 4: # 目标点上的红圈(可选,让目标更明显) canvas.create_oval(x1 + 15, y1 + 15, x2 - 15, y2 - 15, fill='red') root.mainloop()

2025010112 王怡萱
频谱图
import warnings warnings.filterwarnings("ignore") import math import matplotlib.pyplot as plt sample_rate = 44100 window_size = 2048 freq_list = [] amp_list = [] for k in range(window_size // 2): real_part = 0.0 imag_part = 0.0 for n in range(window_size): signal = 800 * math.sin(2 * math.pi * 120 * n / sample_rate) signal += 400 * math.sin(2 * math.pi * 250 * n / sample_rate) signal += 150 * math.sin(2 * math.pi * 1000 * n / sample_rate) angle = 2 * math.pi * k * n / window_size real_part += signal * math.cos(angle) imag_part -= signal * math.sin(angle) amplitude = math.hypot(real_part, imag_part) current_freq = k * sample_rate / window_size freq_list.append(current_freq) amp_list.append(amplitude) plt.figure(figsize=(14, 7), dpi=110) plt.plot(freq_list, amp_list, color='#0066cc', linewidth=1.5) plt.xlim(0, 2000) plt.xlabel("频率 (Hz)", fontsize=13, fontweight='bold') plt.ylabel("信号幅值", fontsize=13, fontweight='bold') plt.title("自制手写DFT算法 音频低频段频谱图", fontsize=15, fontweight='bold') plt.grid(True, alpha=0.4, linestyle='--')


2025010113 石蕊鑫
欧拉坐标值转化为轴坐标系(x,y,z)
import math "euler坐标值=欧拉角=球坐标(r,θ,φ)" def euler_to_xyz(r,θ,φ): x = r * math.sin(θ) * math.cos(φ) y = r * math.sin(θ) * math.sin(φ) z = r * math.cos(θ) return x, y, z # 例:r=5, theta=45° (pi/4), phi=30° (pi/6) r, θ, φ = 5, math.pi/4, math.pi/6 x, y, z = euler_to_xyz(r, θ, φ) print(f"x={x:.4f}, y={y:.4f}, z={z:.4f}")

2025010114 殷佳锐
窗口计时器
# 导入图形界面库,用于制作图形窗口 import tkinter as tk # 创建窗口 window = tk.Tk() window.title("计时器") window.geometry("600x600") # 初始化时间:时、分、秒 hour = 0 minute = 0 second = 0 # 创建显示时间的文字 time_label = tk.Label(window, text="00:00:00", font=("Arial", 100)) time_label.pack(pady=200) # 时间更新函数 def update_time(): global hour, minute, second # 秒加1 second += 1 # 秒满60进1分 if second == 60: second = 0 minute += 1 # 分满60进1时 if minute == 60: minute = 0 hour += 1 # 格式化显示:两位数字,不足补0 time_str = f"{hour:02d}:{minute:02d}:{second:02d}" time_label.config(text=time_str) # 每隔1秒再次更新 window.after(1000, update_time) # 开始计时 update_time() # 窗口主循环 window.mainloop()

2025010115 康静茹
绘制五角星
import turtle t = turtle.Turtle() # 画五角星 for _ in range(5): t.forward(200) t.right(144) turtle.done()

2025010117 李欣栎
绘制五角星
import turtle # 导入绘图库 pen = turtle.Turtle() # 创建画笔 for i in range(5): # 循环5次画五角星 pen.forward(150) # 线段长度 pen.right(144) # 五角星固定转角 turtle.done()

2025010118 陈影
百钱百鸡
#百钱百鸡:公鸡x,母鸡y,小鸡z(数量) #公鸡5r一只,母鸡3r一只,小鸡1r三只 for x in range(0,21): #公鸡最多20只 for y in range(0,34): #母鸡最多33只 z=100-x-y #小鸡数量 #钱为100,小鸡数量为3的倍数 if 5*x+3*y+z//3==100 and z%3 == 0: print(f"公鸡:{x},母鸡:{y},小鸡:{z}")

2025010119 淡郑雪
字母频率统计
英语阅读字母频率统计(不用函数,只输出出现最多前3个字母) # 只统计26个小写英文字母,忽略标点、空格、换行、大写 text = """My Happy Daily Life I get up early every morning. I wash my face and brush my teeth. Then I have breakfast with my family. I like milk and bread very much. After breakfast, I go to school on foot. I like studying and reading books. At school, I play games with my classmates. We are very happy. In the evening, I do my homework and watch a little TV. I go to bed at nine o'clock. I love my simple and happy life.""" # 初始化26个字母计数 counts = [0] * 26 # 遍历文本统计 for char in text: # 转小写 c = char.lower() # 只统计a-z if 'a' <= c <= 'z': idx = ord(c) - ord('a') counts[idx] += 1 # 构造字母+次数列表 letter_num = [] for i in range(26): letter = chr(i + ord('a')) letter_num.append([letter, counts[i]]) # 按次数从高到低排序 letter_num.sort(key=lambda x: x[1], reverse=True) # 只取前三个 print("出现频率最高的前3个英文字母:") for i in range(3): print(f"字母:{letter_num[i][0]} ,出现次数:{letter_num[i][1]}")

2025010120刘司拓
租车系统



2025010121郑舒萍
统计一份试卷中有几个大题几个小题
# 2025年新高考数学I卷统计程序 # 适配多种题号格式,避免统计为0 paper = """2025年普通高等学校招生全国统一考试(新1卷) 一、选择题:本大题共8小题,每小题5分,共计40分. 1.的虚部为( ) 2.设全集,集合,则中元素个数为( ) 3.若双曲线C的虚轴长为实轴长的倍,则C的离心率为( ) 4.若点是函数的图象的一个对称中心,则a的最小值为( ) 5.设是定义在上且周期为2的偶函数,当时,,则( ) 6.帆船比赛中,运动员可借助风力计测定风速的大小和方向 7.若圆上到直线的距离为1的点有且仅有2个,则r的取值范围是( ) 二、选择题:本题共3小题,每小题6分,共18分. 9.在正三棱柱中,D为BC中点,则( ) 10.设抛物线的焦点为F,过F的直线交C于A、B 11.已知的面积为,若,则( ) 三、填空题:本大题共3小题,每小题5分,共计15分. 12.若直线是曲线的切线,则 . 13.若一个等比数列的各项均为正数,且前4项和为4 14.一个箱子里有5个相同的球,分别以1~5标号 四、解答题:本题共5小题,共77分. 15.为研究某疾病与超声波检查结果的关系 16.设数列满足 17.如图所示的四棱锥中,平面,. 18.设椭圆的离心率为,下顶点为A,右顶点为B 19.(1)设函数,求在的最大值""" # 统计大题 big = 0 if "一、" in paper: big += 1 if "二、" in paper: big += 1 if "三、" in paper: big += 1 if "四、" in paper: big += 1 # 修正:适配「数字+中文句号/英文句号」的题号格式 small = 0 for i in range(1, 20): # 同时匹配 "1." 和 "1." 两种格式 if f"{i}." in paper or f"{i}." in paper: small += 1 # 输出结果 print("————试卷统计结果————") print("大题总数:", big, "个") print("小题总数:", small, "个")

2025010122 田昌盛
code制作
import random num = random.randint(1,50) print("🎮猜数字游戏开始!1-50之间") while True: n = int(input("请输入数字:")) if n > num: print("太大啦") elif n < num: print("太小啦") else: print("🎉猜对了!游戏结束") break

2025010124 胡鑫
两个班级低于平均分的人数
# 班级1成绩 class1 = [85, 72, 60, 90, 58, 77] # 班级2成绩 class2 = [88, 65, 70, 55, 92, 68] # 计算班级1平均分 avg1 = sum(class1) / len(class1) # 统计低于平均分人数 count1 = 0 for s in class1: if s < avg1: count1 += 1 # 计算班级2平均分 avg2 = sum(class2) / len(class2) # 统计低于平均分人数 count2 = 0 for s in class2: if s < avg2: count2 += 1 # 输出结果 print("班级1平均分:", avg1) print("班级1低于平均分人数:", count1) print("班级2平均分:", avg2) print("班级2低于平均分人数:", count2)

2025010125 刘芮孜
把excel内容导成字典
# 读取和代码在同一个文件夹里的 data.xlsx,不把第一行当表头 df = pd.read_excel("data.xlsx", header=None) # 把第0列(第一列)当键,第1列(第二列)当值,转成字典 excel_dict = dict(zip(df[0], df[1])) print("转换后的字典:") print(excel_dict) print("类型:", type(excel_dict))

2025010127 刘杨龙
加密
book = {
1: [
"春眠不觉晓",
"处处闻啼鸟",
"夜来风雨声",
"花落知多少"
],
2: [
"床前明月光",
"疑是地上霜",
"举头望明月",
"低头思故乡"
]
}
def get_char_by_pgc(page, row, col):
"""
根据 页、行、列 取汉字
:param page: 页码
:param row: 行号(从1开始)
:param col: 列号(从0开始)
:return: 对应汉字
"""
try:
# 行号转索引
row_idx = row - 1
# 获取指定页的所有行
page_lines = book[page]
# 获取指定行的字符串
line_str = page_lines[row_idx]
# 获取指定列汉字
char = line_str[col]
return char
except:
return "超出书页行列范围"
if __name__ == "__main__":
print("===== 书页行列加密取汉字 =====")
p = int(input("请输入页码:"))
r = int(input("请输入行号(从1开始):"))
c = int(input("请输入列号(从0开始):"))
res = get_char_by_pgc(p, r, c)
print(f"\n第{p}页 第{r}行 第{c}列 选出汉字:{res}")

2025010128 贾姝慧
筛选两个班重名的人
# 1班名单 class1 = ["张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十", "郑十", "林十二"] # 2班名单 class2 = ["王五", "钱七", "小明", "小红", "李二", "孙八", "小张", "小陈", "小林", "小周"] # 把列表转成集合(方便找重复) set1 = set(class1) set2 = set(class2) # 求交集:两个里面都有的就是重名 same_name = set1 & set2 # 输出结果 print("两个班重名的人:", same_name)

任鸿杰 2025010130
from PIL import Image import os old_name = r"C:\Users\qqq\Desktop\实验三\微信图片_20260512225747_16643_394.jpg" new_width = 30 # 打开图片并处理透明通道(解决PNG转JPG报错) im = Image.open(old_name) if im.mode == 'RGBA': im = im.convert('RGB') # 等比例缩放(不变形) scale = new_width / im.width new_height = int(im.height * scale) resized_img = im.resize((new_width, new_height)) # 保存为JPG文件(也可以改成 "缩放完成.png") resized_img.save("缩放完成.jpg") print(" 成功!缩放后的图片已保存为:缩放完成.jpg")

董玥卓 2025010131
第124页 地图加载
# 1. 定义题目中的7×7推箱子地图 game_map = [ [0, 0, 0, 3, 0, 0, 0], [3, 3, 0, 3, 3, 0, 0], [1, 3, 3, 2, 4, 0, 0], [4, 2, 0, 3, 3, 3, 0], [3, 3, 3, 0, 3, 3, 0], [3, 3, 0, 3, 3, 0, 0], [3, 0, 0, 0, 0, 0, 0] ] # 2. 把地图写入 map1.txt 文件 # 按行存储,每行数字用空格分隔 with open("map1.txt", "w", encoding="utf-8") as f: for row in game_map: # 一行数字转字符串,空格隔开 line = " ".join([str(num) for num in row]) f.write(line + "\n") # 3. 从 map1.txt 读取并加载地图 load_map = [] with open("map1.txt", "r", encoding="utf-8") as f: for line in f: # 去掉换行符,分割数字,转成整数列表 row_data = [int(num) for num in line.strip().split()] load_map.append(row_data) # 4. 打印验证 print("✅ 成功加载地图:") for r in load_map: print(r)

李佳雨 2025010132
三个班的优秀学生
# 三个班的成绩数据:每个元素是(姓名,班级,成绩) scores = [ # 一班 ("张三", "一班", 85), ("李四", "一班", 72), ("王五", "一班", 90), ("赵六", "一班", 68), # 二班 ("钱七", "二班", 78), ("孙八", "二班", 88), ("周九", "二班", 65), ("吴十", "二班", 92), # 三班 ("郑一", "三班", 95), ("王二", "三班", 70), ("冯三", "三班", 82), ("陈四", "三班", 60) ] # 1. 先按班级分组,计算每个班的平均分 class_scores = {} # key: 班级名,value: 成绩列表 for name, cls, score in scores: if cls not in class_scores: class_scores[cls] = [] class_scores[cls].append(score) # 计算每个班的平均分 class_avg = {} for cls, s_list in class_scores.items(): avg = sum(s_list) / len(s_list) class_avg[cls] = avg print(f"{cls} 平均分:{avg:.2f}") print("\n===== 高于所在班级平均分的同学 =====") # 2. 筛选高于所在班级平均分的人 for name, cls, score in scores: if score > class_avg[cls]: print(f"姓名:{name} | 班级:{cls} | 成绩:{score}")


浙公网安备 33010602011771号