CSCI 1133 Fall 2024 Homework 09Python

3天干完6个月的活,Claude把模型搬上AMD 一条挺刺激的消息:Anthropic 给投资人的材料里有一张幻灯片,写着它的 Claude Mythos Preview 只花了大约​,就摸清了怎么让另一个 Claude 模型在 AMD 的 MI355X 上跑起来。同一处还写了个对照数字:过去给一块新芯片做推理适配,通常要几十名工程师、​。3 天对 6 个月,这个比值太扎眼,当天中文互联网上就冒出一堆「英伟达的护城河塌了」的说法。我把能翻到的材料都翻了一遍,越看越觉得,塌掉的那一小块是真的,可塌的位置和很多人想的不一样。 阅读详情

Java Python CSCI 1133, Fall 2024

Homework 09

Due:  6:00 pm, Tuesday, November 5, 2024

Purpose: The primary purpose of this assignment is to get practice reading and writing from files.

Instructions: This assignment consists of 4 problems, worth a total of 30 points.

Because your homework file is submitted and tested electronically, the following are very important:

●   Submit the file called hw09.py to the Homework 09 submission link on Gradescope by the due date deadline.  You don’t need to submit the sample files.

● Your program should run without errors when we execute it using Python 3.

The following will result in a score reduction equal to a percentage of the total possible points:

● Bad coding style. (missing documentation, meaningless variable names, etc.) (up to 20%)

● Breaking constraints (up to 40%)

A note on break: While the break keyword can be a useful tool forgetting out of loops early, it tends to be misused by intro students to get out of writing a proper loop condition. So for the purposes of this class, the break keyword is considered bad style. and will lose you points.

Documentation:

Use the following template for EVERY function that you write.  The docstring below should be placed inside of the function, just after the function signature.

'''

Purpose:

Parameter(s):

Return Value:

'''

Download the hw09files.zip archive from Canvas, and extract the files somewhere you can easily find them.  You’ll want all the files to be present in whatever directory   you’rerunning Python from.  Create a file called hw09.py in the same directory as all  the test files.

Problem A. (5 points) Total Hours

The employees at Holistic Synergies, Ltd. submit their timesheets indicating how many hours they’ve worked each day over the past week as a text document containing 7 integers, one per line.  For example, the contents of employee1.txt:

0

5

2

8

7

8

0

would indicate an employee that worked 0 hours on Sunday, 5 on Monday, 2 on Tuesday, 8 on Wednesday, 7 on Thursday, 8 on Friday, and 0 on Saturday.  Employees are required to work shifts that are in increments of full hours, so you’ll never see a decimal value present in the timesheet.

We want to compute the total hours for a given week; in the above example, that would be 0+5+2+8+7+8+0 = 30.

Write a function total_hours(filename) that takes in one parameter, filename, which should be a string representing the name of a file that contains an employee’s hours worked, formatted as described above.

●   The function should return the total amount of hours the employee worked.

You can assume for this problem that the specified file does exist in the directory you’rerunning Python from: no need for a try-except block to avoid FileNotFound errors.

Hints:

● Remember to close any files you open.

●   The information from each line will always be read in as a string, even if it consists only of digits.  Use the int() function before adding it to your total.

Examples: (assumes that the files in the hw09files.zip archive are in the same directory you’re running Python from):

if name == ' main ':

print(total_hours('employee1.txt')) #30

print(total_hours('employee2.txt')) #22

print(total_hours('employee3.txt')) #40

Problem B. (7 points) Adding Day Names

To make the timesheets easier to read, HR has decided to require that employees resubmit all timesheets so that each line contains the day of the week, followed by a colon and a space, and then the number of hours worked.

The name of the new file should be the same as the old file, but with ‘labeled_ ’ concatenated to the beginning.  So if we ran the function on the employee1.txt file:

0

5

2

8

7

8

0

the resulting labeled_employee1.txt file would look like this:

Sunday: 0

Monday: 5

Tuesday: 2

Wednesday: 8 Thursday: 7

Friday: 8

Saturday: 0

Write a function label_days(filename) that takes in one parameter, filename, which should be a string representing the name of a file that contains an employee’s hours worked, formatted as described above.

●   The function should create a new file which has the same name as the original, but with 'labeled_' concatenated to the beginning. CSCI 1133, Fall 2024 Homework 09Python

●   The new file should have the same numbers on each line, but each number

should be preceded by the day of the week (starting with Sunday), then a colon, then a space.

●   This function should not return anything.

You can assume for this problem that the specified file does exist in the directory you’rerunning Python from: no need for a try-except block to avoid FileNotFound errors.

Hints:

● Remember to close any files you open.

Examples:

For this problem, we’re not checking the return value (which is why there’s no expected output for any of the test cases below).  You must instead produce the correct output file for each test.

Inside ofhw09files.zip we’ve included three test files: employee1.txt, employee2.txt, and employee3.txt.

●   For each test file employeeX.txt, we’ve also included a file with a name of the form. correct_labeled_employeeX.txt, which is what the corresponding

labeled_employeeX.txt should look like.

if name == ' main ':

label_days('employee1.txt')

label_days('employee2.txt')

label_days('employee3.txt')

Problem C. (9 points) Stretching a 3D Model

In computer graphics, 3D objects are stored in files that are meant to be loaded anddisplayed on the screen.  Although multiple file formats exist for 3D models, OBJ is one of the most commonly used.  These files are plain text ending in .obj that contain the following:

1)  A list of vertices that specifies the x,y,z coordinates of each point in 3D space

2)  A list of faces, each of which specifies the index number of three points that form. a triangle

Each vertex is listed on one line, and begins with the letter v.  The x, y, and z coordinates are included next, separated by spaces.  After all the vertices are done, each face is then listed on one line beginning with the letter f.  The three index numbers are included next, starting with 1, also  separated by spaces.  For example, this OBJ file contains a single triangle and would be displayed as follows:

Write a function stretch_model(fname_in, fname_out) that reads all the vertices and faces in the OBJ file specified by the string fname_in.  The function should then transform. the vertices to stretch the model by a factor of 2 along the y-axis, and then save the transformed vertices and faces to a file specified by the string fname_out.  This function should return the total number of vertices in the file.

If the specified file fname_in does not exist, stretch_model should instead return -1.

To stretch the model along the y-axis, the y-coordinate for each vertex should be multiplied by 2. The x and z coordinates should not be affected.

So, for the example given above, the output file would look like this (note that due to the OBJ model viewer automatically adjusting the boundaries, the image looks shortened rather than stretched):

You can use the example OBJ files in hw09files.zip on Canvas to test your function.  Verify that your output looks correct using this online viewer: https://3dviewer.net/ .

Hints:

●   You only need to alter the vertex lines (the ones starting with ‘v’); the lines starting with ‘f’ can just be copied directly from the input file into the output file.

●   If you want to see text contents of an OBJ file rather than the 3D model, be sure to open the file with a text editor (like VS Code) and not something like 3D Model Viewer.

● You can convert a line from the OBJ file into a list with the statement

listName = stringName.split(' ').  Using a space as a delimiter rather than leaving it blank will ensure that you don’t lose the newline character at the end.

●   You can convert this list back into a string with the statement stringName = ' '.join(listName).

Constraints:

● All files must be properly opened and closed.

●   You must use a try-except block to prevent a FileNotFoundError in the case that the given file does not exist.

Note: For this problem getting the correct return value is not sufficient: you must also match the expected output file.  See the sample output files in your hw09files.zipfolder to see what each    should look like.

Examples (assumes that missing.obj does not exist within your current directory):

if name == ' main ':

print(stretch_model('missing.obj', 'doesntmatter.obj')) #-1

print(stretch_model('triforce.obj', 'triforce_stretched.obj')) #9

print(stretch_model('teapot.obj', 'tall_teapot.obj')) #3644

Example Screenshots: (using https://3dviewer         

如何处理动态语言(Python / JS)的“隐形”调用链? 本文揭示动态语言(Python/JS)中静态AST解析导致调用链“断链”的核心问题,提出通过运行时追踪补全图谱的解决方案。基于Code-Graph-RAG的cgr trace机制,分别利用pytest插件与V8 Profiler捕获真实调用路径,将动态边合并至静态图谱,并在权重体系中提升动态边优先级。实践表明,该方法可显著提升图谱覆盖率,实现“结构+行为”双视角理解代码,为MCP与Rerank系统提供可靠支持。 阅读详情

相关推荐

Playwright: Pytest vs Library vs LibraryAsync:三者如何选?

Python中Playwright的3个Target:Pytest(推荐用于E2E自动化测试,支持报告、并行、重试)、Library(同步脚本,适合爬虫与简单任务,需手动管理浏览器)、LibraryAsync(异步脚本,适用于高并发批量操作)。选择依据:测试项目选Pytest,轻量脚本选Library,高并发场景选LibraryAsync。

SmallBull的博客 228

本地化部署 DeepSeek,构建单细胞与空间转录组 AI 分析平台

本地化部署 DeepSeek,构建单细胞与空间转录组 AI 分析平台

weixin_53637133的博客 187

告别调试烦恼:用Lattice Diamond手把手教你JTAG烧录FPGA(附SRAM/Flash模式详解)

本文详细介绍了使用Lattice Diamond软件进行JTAG烧录FPGA的全流程,包括SRAM临时调试和Flash固化的核心区别。从环境准备、硬件连接到文件准备、烧录模式选择,再到典型问题排查和高级技巧,手把手教你快速掌握FPGA烧录技术,提升开发效率。

weixin_42569329的博客 498

【第 009 讲】全面掌握 Python 注释:注释的定义与作用 | 单行注释 | 三引号与多行注释 | 注释使用的最佳实践

本文系统讲解 Python 注释的完整知识体系:从注释的定义与作用讲起,梳理单行注释的书写位置、临时屏蔽用法与 PEP 8 排版规范,剖析注释被忽略的底层机制;进而说明三引号字符串的本质与嵌套问题;最后给出注释使用的三条实践原则,帮助读者写好可读性高的注释。

大模型全栈工程师 · Thanks_ks 1167

Mathtype公式排版避坑指南:固定行距20磅下如何完美显示上下标(实测有效)

本文针对学术论文在固定行距20磅要求下,Mathtype公式上下标显示不全或被裁剪的问题,提供了实测有效的解决方案。文章深入剖析了固定行距与公式排版的冲突原理,并详细指导用户通过调整Mathtype的“定义间距”参数(如下标深度、上标高度),以及利用“格式化公式”功能进行批量处理,确保公式在严格遵守期刊格式要求的同时清晰完整显示。

weixin_29228203的博客 1071

机械臂TCP标定实战:从四点法到六点法的精度跃迁

本文详细解析机械臂TCP标定技术,从基础的四点法到高精度的六点法实现精度跃迁。通过工具坐标系与基坐标系的转换原理,结合实战案例展示六点法如何将装配合格率提升至99.5%,并分享环境控制、操作技巧等提升标定精度的关键要素。

weixin_29038345的博客 901

Python 的 yield from 到底转发了什么:拆开 send、throw 和那个 return 值

很多人把yield from记成「省一层 for 循环的语法糖」。写和写,结果看着一样,于是就当它只是少敲几个字。这个理解会在三个地方翻车:调用方.send()的值送不进去、子生成器return的值拿不到、异常和close()传不下去。yield from真正做的事是,外层生成器退成一个透明通道。本文所有输出来自本机 CPython 3.13.14 实测。yield from不是循环,是委托——nextsendthrowclose四个方向的流量全部直通子生成器,并且子生成器return。

小小张说故事的博客 163

联想ThinkPad声卡驱动安装避坑指南:从E470到X1 Carbon的通用解法

本文详细介绍了ThinkPad声卡驱动安装的全流程,从硬件识别到驱动获取、安装技巧及深度排错。涵盖E470到X1 Carbon等不同机型的通用解法,帮助用户解决音频驱动问题,提升使用体验。重点讲解了声音驱动的精准识别和安装策略,确保系统稳定运行。

weixin_29207439的博客 713

AI全栈实战 | 3.9-01 爬虫入门:requests 加 BeautifulSoup 三分钟跑通,但 90% 的人栽在这 4 个“礼貌“问题上

⚠️:本文内容仅用于。请遵守目标站点的服务条款与相关法律法规,不得对目标服务造成负担,不得采集、传播个人隐私数据。技术是中性的,边界在你手里。爬虫的入门技术(requests 发请求 + BeautifulSoup 解析)三分钟就能学会。真正区分"会用爬虫"和"会做爬虫的人"的,是这篇我们跑通"请求→解析→存储"的最小闭环,然后重点把"合规与礼貌"这根弦给你绷上。

源码获取 | 运行部署 | 定制二开修改,如果回复不及时请耐心等待,请见谅。 442

HDMI端口辐射(EMI)超标解决方案

HDMI端口辐射(EMI)超标解决方案 一、HDMI EMC设计要求: 1、HDMI EMC设计原理图 ( 图 一 ) 2、HDMI元件选型及参数说明:(图一所示) a.L510、L511、L512、L513使用专业EMI共模滤波器(普通共模电感寄生电容太大,会导致TMDS差分阻抗匹配测试失败),阻抗值为90Ω~100Ω(两路共模滤波器型号:CMF1210DH900MFR;四路共模滤波器型号:CMF2010DH101MFR), b.U1、U2为排式ESD(ESD排型号:ESD0524PA),越低的结电容

ltqdxl的博客 1万+

Spring Boot Swagger未授权访问漏洞:原理、风险与修复方案详解

在微服务架构中,API文档管理是开发与运维的重要环节。Swagger作为RESTful API文档生成与调试的标准化工具,通过OpenAPI规范自动生成交互式接口文档,极大提升了开发效率。然而,其默认配置往往缺乏访问控制,导致文档端点直接暴露,形成未授权访问漏洞。从技术原理看,该漏洞源于Spring Boot等框架集成Swagger时,相关端点未纳入安全框架的拦截范围,攻击者可通过扫描常见路径获取完整的接口定义与数据结构。这不仅会造成敏感信息泄露,更可能成为越权操作、数据篡改等深度攻击的入口点。在工程实践中

weixin_42524171的博客 504

从一段视频到可漫游的 4D 有声场景:思路拆解与最小复现手记

只需一段手机视频,你就能生成可"走进去"的 4D 有声场景:转头时狗叫声方向随之变化,走近时声音更清晰。本文拆解 Video-to-4DAVScene 的核心思路,手把手带你用几十行 Python 搭出最小管线,把视频中的运动物体变成带空间位置的声源,并附上三个真实踩坑的排障经验,代码可直接跑。🎧

helloagent的博客 246

uniapp - 实现移动端H5微信公众号网页内置浏览器中预览和下载word文档(doc)、excel表格(xls)、ppt文稿、pdf文档等文件,微信内部打开预览和下载到本地详教程,兼容安卓苹果手机

uni-app,微信公众号,h5,移动端,web平台端,网页,网站,Uniapp微信公众号H5网站,内置浏览器下载文档,如何在微信浏览器中预览office文件,word文档,excel文档,pdf文档,ppt文档,office,微信内置浏览器下载文件,下载文件,在微信浏览器里面实现下载任意文件,H5需要在微信浏览器中下载excel文件,UniApp实现网页在微信内置浏览器中下载文件详细教程,安卓点击下载会提示打开浏览器,后端返回流文件,如何解决无法下载文件,跳转至浏览器下载文件,发送到电脑微信,安卓,苹果,

🏆 前端领域优质创作者 1万+

【每天一个 Python 小案例30】Python 基础知识综合小项目:我的工具盒

作为系列收官,本篇把前 29 篇的知识点合成一个能直接用的命令行工具"我的工具盒":计算器(用 ast 解析表达式,不碰 eval)、单位换算与温度转换(一张换算表 + 特例分支)、记账与分类统计(Decimal + JSON 持久化)、以及用"字典当命令表"把菜单和业务逻辑解耦的主循环。文中对比了 eval 的安全隐患与 ast 白名单的做法,解释了 lambda 闭包在字典里的写法与晚绑定陷阱,并在最后给出整个系列的知识地图,把变量、数据结构、控制流、函数、类、异常、文件、标准库八块内容对应到具体篇目。

xinjiyaya的博客 432

基于STM32L4XX 、HAL库的TMP144YFFR数字温度传感器驱动应用C语言程序设计

define TMP144_ADDRESS 0x00 // 默认为全局地址,用于单器件或MDA命令。#define TMP144_CMD_READ_TEMP 0x00 // 读取温度寄存器命令。if (temp_raw & 0x800) { // 判断第11位(符号位)

PP_Cottage的博客 92

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

双路径优化+双容差校准

默认使用向量化路径处理常规数据,当检测到内存非连续或需要极致短路性能时,自动切换至 Numba JIT 路径。“当 CI 宽度中位数为 $W$ 时,实际判定容差为 $10^{-12} + 10^{-9} \times W$"针对表征谱算子 2 的实际输出量纲(例如 $10^{-3}$ 至 $10^3$),调整。准确标记了哪些数组被复制。非短路、静默拷贝风险、量纲耦合容差),本方案重构了核心逻辑。,并完善审计元数据以记录内存拷贝状态。, 确保在不同量纲下判定标准的一致性。,否则需排查上游数据生成逻辑。

2301_77211362的博客 202

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

yolo 和 deft 算法的区别

你应该是打错了:是,不是 defrat;

曾大强博客 274

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

两张表合并之后,行数悄悄多了一倍

pandas merge 行数异常膨胀源于右表键不唯一,导致数据静默复制。实测显示,未聚合的右表(756行)与左表合并后行数增至504行,合计膨胀3.5倍,但无报错。validate 参数仅在检查键唯一性时有效,one_to_one 和 many_to_one 可拦截问题,但需结合 duplicated() 前置检查。正确做法为先按键聚合右表,再合并,避免重复。建议合并前后核对行数、合计,并使用 indicator=True 排查匹配情况,确保数据一致性。

patrickstar231的博客 251

蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级 备考:莫队算法离线区间查询详解

备赛进行时:第十八届蓝桥杯软件赛报名已于 2026-10-08 10:00 开启、12-18 14:00 截止,省赛定在 2027-04-10(C/C++·Python 程序设计 9:00–13:00);中国电子学会 2026 年 12 月软件编程(C/C++ 一级至十级、Python 一级至六级)考级报名 9/23–12/2 16:00、统考 12-12;全国青少年信息素养大赛 2026—2027 赛季算法应用主题赛也已进入复盘练兵窗口。

IT_Scratch的博客 184

我用 200 行代码写了个“代码屎山检测器“,扫完公司的老项目后我沉默了

这个工具不能帮你把屎山铲平,但至少能让你知道自己面对的是多大的山,也能在代码评审时用数据说话——“这个 PR 把圈复杂度从 12 推到了 18,能不能拆一下?毕竟,不能量化的东西,就没法改进。

xixiaoyunya的博客 272

智慧农业实战:育秧车间秧盘计数与苗情分级的Python实现

首先,建立统一的数据结构,保存每盘秧苗的编号、批次、覆盖度、叶色得分和播种天数。A = "壮苗"B = "合格苗"C = "弱苗"@dataclassdays: int。

荆棘鸟智能的博客 138

Java Arrays.asList 常见坑详解|UnsupportedOperationException、数组联动、基本类型 bug

解析 Arrays.asList 常见开发陷阱,演示 UnsupportedOperationException、底层数组引用共享、基本类型数组问题,区分 Arrays 内部 ArrayList 与 java.util.ArrayList,给出数组转 List 的各种场景正确代码。

weixin_42617033的博客 511

【每天一个 Python 小案例29】Python 实现商品购物车

本篇实现一个购物车:商品目录、加入商品、修改数量、移除商品、查看小计、计算满减与 VIP 折扣、结算扣库存。核心设计是"目录与购物车分离"——目录存商品主数据,购物车只存 {商品编号: 数量};金额一律用 Decimal 并做 ROUND_HALF_UP 舍入。折扣部分讲清阶梯满减的匹配顺序(阈值从高到低、命中即停)与叠加顺序(先满减、后打折),并用一次完整结算演示 706 元如何变成 613.70 元。

xinjiyaya的博客 220

Python的字典

Python字典是存储键值对的数据结构,通过键(key)快速查找对应的值(value)。可使用{}定义,支持增删改查操作:通过dict[key]查询或修改值,get()方法安全获取并设置默认值,del dict[key]删除键值对,keys()、values()和items()用于遍历。items()结合双变量循环可高效遍历所有键值对,提升代码可读性与灵活性。

qq_43010954的博客 199

黄仁勋走了,护城河留下了什么

11 月 12 日,英伟达董事会批准黄仁勋辞去总裁、CEO 和董事职务,即刻生效,CFO 克雷斯出任临时 CEO;股价开盘一度跌 14.35%,收盘只跌 4.34%,市值单日蒸发 1820 亿美元;本文把「创始人走了护城河就没了」这个流行说法拆开——CUDA 还在,但 CUDA 正在被 Claude 三天凿穿,真正决定下一段路的是三个可以核对的东西:治理结构、决策机制、以及下一个百亿美元由谁拍板。

领码SPARK - 以无代码之星火,燎原数字之未来! 187

【AI 开发从入门到进阶 · 09】RAG 实战:用 Embedding + FAISS 从零搭建本地知识库问答(含切分、重排与幻觉控制)

本文系统讲解RAG(检索增强生成)的实现与优化,从为何选择RAG而非提示工程或微调出发,完整演示一条可运行的中文RAG链路:文档加载、递归切分、向量化、FAISS索引构建、混合检索与Prompt生成。重点剖析五大关键环节——切分策略、Embedding选型、混合检索、重排(Rerank)及幻觉控制,并强调分模块评估的重要性。附常见问题排查与生产实践建议,为构建高效、可信的企业知识问答系统提供完整指南。

信息安全领域优质创作者|操作系统领域专家 95
上一篇: FIN B281F Finance for Managers 2024Java
下一篇: ENT203TC Leadership and Communication Academic Year 2024‐2025
priorityqueue3
博客等级 码龄2年 252粉丝 40原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值