代写CSCI 1133, Fall 2024 Homework 09代写留学生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.

●   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.net/)



热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图