Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


CSCI 141 Project 1

In our first project, your task is to create three short programs. These can be completed using only the material introduced in Module  1. For each program, we suggest that you write an algorithm as a simple numbered list of steps and then create a Python implementation.

You will submit the three programs as separate files with the extension .py (NOT NOTEBOOK FILES). Submit via Gradescope. You will have the opportunity to submit your files for auto-grading several days in advance of the deadline. You may re-submit as many times as you would like up until the deadline. Only your LAST submission will be graded and will count towards your score, so it must be complete. We will not collate files from prior submissions.

This project deals with images and image resolution. For further explanation, this is a nice summary you can consult: https://guides.lib.umich.edu/c.php


About the instructions

In a computer science course as well as in a job where you create software, instructions are   often referred to as specifications. The specifications are not optional – you must follow them exactly even if you don’t agree with them.

The vast majority of bugs in code in this course arise from not following the instructions. The  vast majority of common questions are answered in the instructions. The instructions provide hints for places where we think you will struggle – these are included to help you.

You should be constantly referring to the instructions as you write your code. Reading them once and then setting them aside is a recipe for stress, buggy code, and a lot of extra time spent on    projects. Use all of the information in the instructions and follow them exactly. You can expect to read and refer to them at least 10-20 times, and perhaps much more than that for more             complex projects.


Program One: Megapixels

A pixel is the smallest element of an image – images are made up of pixels. You can think of an image as a grid of pixels. The number of pixels in an image can be expressed in several ways.   We might say that an image is 2500 x 1080 pixels where the 2500 is the number of pixels per   row and the 1080 is the number of pixels per column. There are 2700000 total pixels. We can   express this number in megapixels – one megapixel is one million, or 106, pixels. There are 2.7 megapixels.

Write a program that takes two inputs: 1) The number of pixels per row; this will always be a

positive integer, e.g. 1000, and 2) The number of pixels per column; this will always be a positive integer, e.g., 1000.

Your program should calculate and print out the number of megapixels contained in the image.

For consistency, format the program's interaction as illustrated in the following examples. Do not vary the phrasing, capitalization, spacing, etc. We will expect your outputs to match exactly (and they will fail the automated tests if they don’t!), so note the text carefully. You should not be       rounding or truncating the decimal values in any way.

How many pixels are there per row? 1200

How many pixels are there per column? 1000

A 1200 x 1000 image is 1.2 megapixels

How many pixels are there per row? 1234

How many pixels are there per column? 5678

A 1234 x 5678 image is 7.006652 megapixels

Your program must be called megapixels.py. Inputs for row and columns pixels will always be positive integers. Other inputs will not be tested.

Write out the steps on paper first. Create and input and output diagram like we did in class and work out the algorithm before you write any code.

Your program should be well-styled. Take a look at the programs given in the class notes for examples. More specifically, what does “well-styled” mean? Among other things: Use variable names that make sense, and avoid using keywords. Avoid extraneous variables and casting variables that are already the correct type. Use appropriate structures and syntax.


Program Two: Find the height

Have you ever tried to make an image larger and ended up with something that looks fuzzy and hard to read? This is due to low resolution.

What is commonly referred to as resolution (though it is more properly called pixel count) relates to the quality of an image. We can describe resolution in many ways, one of which is pixels per    inch or ppi.

If an image has 1000 pixels per row and the width is 5 inches, the resolution would be 200ppi,    which is considered (in some circles) photo quality resolution – it’s pretty good. If an image has   1000 pixels per row and the width is 100 inches, it has 10ppi which is pretty terrible – it will look like fuzzy squares.

Ideally when we calculate the resolution based on the width, the resolution for the height should  match to avoid distortion. Let’s go back to the image that has 1000 pixels per row and a width of 5 inches. The resolution based on the width is 200 ppi. If the image also has 1000 pixels per       column, we would want the height to be 5 inches to achieve 200 ppi.

Consider a second image that has 1000 pixels per row and a width of 5 inches. There are 2000 pixels per column. We would want the height of the image to be 10 inches to achieve 200 ppi.

Write a program that takes three inputs: 1) The number of pixels per row; this will always be a positive integer, e.g. 1000, 2) The number of pixels per column; this will always be a positive   integer, e.g., 1000, 3) The width of the image in inches; this will always be a positive number   but may not be a whole number

Your program should calculate and print out both the resolution in ppi as well as the height        necessary to achieve that resolution. Resolutions must be whole numbers. We will round down any floating point values. This means if you calculate a resolution of 104.42, you would report it as 104.

For consistency, format the program's interaction as illustrated in the following examples. Do not vary the phrasing, capitalization, spacing, etc. We will expect your outputs to match exactly (and they will fail the automated tests if they don’t!), so note the text carefully. In particular, the


resolution is reported as a whole number and the height should be reported with two decimal places exactly (these are rounded normally, as in >0.5 rounds up and <=0.5 rounds down).

How many pixels are there per row? 1000

How many pixels are there per column? 1000

What is the width of the image (in inches)? 5

The height of the image should be 5.00 inches to ensure resolution of 200ppi


How many pixels are there per row? 1550

How many pixels are there per column? 750

What is the width of the image (in inches)? 5

The height of the image should be 2.42 inches to ensure resolution of 310ppi

Your program must be called find_height.py. Inputs for row and columns pixels will always be positive integers. Inputs for image width will always be positive numbers. Other inputs will not be tested.

Your program should be well-styled. Take a look at the programs given in the class notes for examples. Be sure to format the output correctly.


Program Three: Resizing an image

In the Program 2, you determined the height necessary to achieve a particular resolution if the image width was already set. A more common problem is to figure out what size to make an    image in terms of both width and height to achieve a particular resolution.

We will consider 3 resolutions: 72ppi which is sometimes referred to as screen resolution, 200ppi which is sometimes considered photo resolution, and 600 ppi, which is high resolution.

Suppose we have an image that is 1000 x 1000 pixels (if you don’t know how to read this      notation, go back and read the instructions for the other programs). If we want to achieve a  resolution of 200ppi then we would scale the image to 5 inches by 5 inches – this gives 200   pixels in every inch. If we want to achieve a resolution of 72ppi, then we would scale to . The image to (approx.) 13.89 inches by 13.89 inches – this gives 72 pixels per inch.

In the file, resize.py, you are provided with two lines of code. Your task is to complete the remainder of the program so that it meets the specifications explained below.

Your program will take three inputs from the user. The first is the number of pixels per row; this will always be a positive integer, e.g. 1000. The second is the number of pixels per column; this will always be a positive integer, e.g., 1000.

The third input is an integer used to select the resolution. This will make use of the provided line of code: resolutions = ['72 ppi', '200 ppi', '600 ppi']

You are not permitted to change this line of code. Use the integer entered to select the                appropriate item from the list (examples shown below). We have not learned about conditionals   and you should not and do not need to use them. This is the part of the instructions that you really need to read and re-read if you want all of the manual grading points: You     must use the list provided as is. This means not taking the values out and making a new list with different values in it, not editing the code given, not assigning each item in the list a single          variable and using that, not creating your own list with the same name to use. You must directly


index the list given without changing the list given in any way. And again, no conditional           statements are allowed. Once you’ve obtained an item from the list, you will need to process it.

You will also make use of the second provided line of code: names

= ['Standard', 'Photo', 'High']

This will appear in your output (see below). Again, you MUST directly index the list and may   not change the list or create a new list or a series of new variables as described above. What you do with the second list is identical to what you do with the first list.

If you get stuck on how to make use of the list, look at the last checkpoint question for Section 1B. It is VERY similar to what you need to do here.

For consistency, format the program's interaction as illustrated in the following examples. Do not vary the phrasing, capitalization, spacing, etc. We will expect your outputs to match exactly (and they will fail the automated tests if they don’t!), so note the text carefully. In particular, the        width and the height should be reported with two decimal places exactly (these are rounded        normally, as in >0.5 rounds up and <=0.5 rounds down).


How many pixels are there per row? 1000

How many pixels are there per column? 1000

Enter 1 for standard resolution, 2 for photo quality resolution, or 3 for high resolution:

2

The image should be sized to 5.00 in by 5.00 in. for Photo Resolution

How many pixels are there per row? 2000

How many pixels are there per column? 1550

Enter 1 for standard resolution, 2 for photo quality resolution, or 3 for high resolution:

3

The image should be sized to 3.33 in by 2.58 in. for High Resolution

Your well-styled program should be submitted in a file called resize.py (the same name as the    template file given to you). Inputs for the row and column pixels will always be positive integers. Inputs for the resolution will always be 1, 2, or 3. No other inputs will be tested.


SUBMISSION EXPECTATIONS

Project1.pdf A PDF document containing your reflections on the project. This does not need to be long. Include your overall impression, anything you found particularly interesting/difficult,   and any discoveries you may have made. You must also cite any sources you use. Please be aware that you can consult sources, but all code written must be your own.

megapixels.py Your implementation of program one, following the format specified. find_height.py Your completed implementation of program two, following the format specified. resize.py Your implementation of program three, following the format specified above.