Pixels and Colors

Most people want to do a lot more to pictures than just display them and crop them. If you do a lot of digital photography, you may want to remove the red-eye caused by your camera flash. You might also want to convert pictures to black and white for printing, highlight certain objects, and so on. To do these things, you must work with the individual pixels that make up the image. The media module represents pixels using the RGB color model discussed in the sidebar on page 72. Module media...

Images

Python Programming Madeleine

Now that we have seen the basic features of modules, objects, and methods, let's look at how they can solve real-world problems. For our running example, we will write some programs that display and manipulate pictures and other images. Suppose you have a file called pic207.jpg on your hard drive and want to display it on your screen. You could double-click to open it, but what does that actually do To start to answer that question, type the following into a Python prompt gt gt gt import media...

Defining Your Own Modules

Section 2.1, The Big Picture, on page 17 explained that in order to save code for later use, you can put it in a file with a .py extension. You can then tell Python to run the code in that file, rather than typing commands in at the interactive prompt. What we didn't tell you then is that every Python file can be used as a module. The name of the module is the same as the name of the file, but without the .py extension. For example, the following function is taken from Section 2.6, Function...

Computer Science Exercises

Here are some exercises for you to try on your own 1. Import module math, and use its functions to complete the following exercises a Write a single expression that rounds the value of -4.3 and then takes the absolute value of that result. b Write an expression that takes the ceiling of sine of 34.5. 2. In the following exercises, you will work with Python's calendar module a Visit the Python documentation website at http docs.python. org modindex.html, and look at the documentation on the...

Write A For Loop To Read The Contents Of Alkaline Metals.txt And Store It In A Nested List With Each Element Of The

Here are some exercises for you to try on your own 1. Assign a list that contains the atomic numbers of the six alkaline earth metals beryllium 4 , magnesium 12 , calcium 20 , strontium 38 , barium 56 , and radium 88 to a variable called alkaline_earth_metals. 2. Which index contains Radium's atomic number Write the answer in two ways, one using a positive index and one using a negative index. 3. Which function tells you how many items there are in alkaline_ earth_metals 4. Write code that...