Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use python please and if you could explain the code that would be awesome. Thanks CS5001-5003 -- Lab 5 - Files and More! February 4

image text in transcribed
image text in transcribed
Use python please and if you could explain the code that would be awesome. Thanks
CS5001-5003 -- Lab 5 - Files and More! February 4 28, 2020 (Due before end of next Lab) With thanks to pevious CS5001-5003 Instructors Programming + Code Review It is almost always OK, and generally encouraged, to program in a pair (or small group) when working on labs. Please also take turns doing informal "code reviews of each other's work, when you code separately. (Please refer to the handout for Lab 3 for the procedure to conduct a Code Review.) Lab Part 1. Reading and Writing binary files A. Write a Python program, bincopy.py, that copies a binary file. It should name the resulting file the same as the original but with "_copy" added to the name. For example, turtleart.png should be copied to turtleart_copy.png. B. Write a variation of A that creates an encrypted version of the original file with an appropriate name (e... turtleart crypt.png. The "encrypted" form should be calculated by adding a constant, CAESAR, between 0 and 255 to each byte. However, if the resulting value would exceed 255, you should use the % function to ensure if falls into that range. Try looking at the resulting file with a web browser. C. Write a variation of B that, given the value of CAESAR, recovers the original contents of an encrypted binary file (eg turtleart_recovered.png). Again, try looking at the resulting file with a web browser. Lab Part 2. Working with Loops and Importing Python Files A Create a file mymain.py which contains a function, main() that prints a greeting to the user when it is called. Include a call to main() at the end of the file. B. Create a file myfuns.py which defines the following functions: mymax(), which accepts as input a list of integers and returns the largest one mymin, which accepts as input a list of integers and returns the smallest one myavg0, which accepts as input a list of integers and returns the average mymediano), which accepts as input a list of integers and returns the median mymode(), which accepts as input a list of integers and returns the mode C. Include the following code at the bottom of myfuns.py if name main : print("This is a library of functions, so", this should not print when used as a library.") D. Modify main.py to import myfuns.py. Edit main() to incorporate test calls to each of the five functions in myfuns.py, with sample data. Run Page 1 of 2 your updated main() progra. Verify that the correct values are being returned, and print the results to the user's screen. Did the print statement from the bottom of myfuns.py appear? Why or why not? E. [Optional] Modify any functions within myfuns.py that could potentially divide by zero, depending on the list of integers provided. Add a try/except clause to guard against this error. F. (Optional] Modify main to read the list(s) of integers from a 'text file, calling all five functions on each list, with reasonable formatting between lists. Assume that the file might be large, so it wouldn't be ideal to read the entire file in at one time

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions