Introduction To Computing and Programming in Python 4th Edition Solution Manual
Introduction To Computing and Programming in Python 4th Edition Solution Manual
Chapter 1
1.1 Every profession uses computers today. Use a Web browser and a search engine like
Google to find sites that relate your field of study with computer science or computing or
computation. For example, search for “biology computer science” or “management
computing.”
A good answer should have at least 2-3 links. For example, for “biology” some good
links would be:
http://www.brown.edu/research/projects/computational-molecular-biology/
http://www.sciencedirect.com/science/article/pii/S0960982201000811
http://www.biomedcentral.com/1471-2105/12/120
1.2 The 2013 Nobel Prize in Chemistry was in some sense a Nobel Prize given for work
in computer science. What was the role of computers in that Nobel Prize?
Computers were used to simulate the behavior of large molecules in a brand new way
combining classical and quantum physics.
1.3 Text characters are encoded in different ways. The bottom level is always binary in
bytes, but a different binary pattern can be used to represent different characters. Two of
these encodings are ASCII and Unicode. See if you can do Web searches on ASCII and
Unicode. What’s the difference between ASCII and Unicode? Why would we need
Unicode if we already had ASCII?
The major difference between ASCII and Unicode is the amount of characters both hold.
ASCII has 128 characters, while Unicode has over 110,000 characters. Unicode is largely
used for non-Latin letters, such as Chinese characters,
1.4 Consider the representation for pictures described in Section 1.4, where each dot
(pixel) in the picture is represented by three bytes, for the red, green, and blue
components of the color at that dot. How many bytes does it take to represent a 640 by
480 picture, a common picture size on the Web? How many bytes does it take to
represent a 1024 by 768 pictures, a common screen size? (What do you think is meant
now by a “three megapixel” camera?)
A “three megapixel” camera means that the camera can capture images with three million
pixels.
1.5 One bit can represent 0 or 1. With two bits you have four possible combinations 00,
01, 10, and 11. How many different combinations can you make with four bits or eight
bits (one byte)? Each combination can be used to represent a binary number. How many
numbers can you represent with 2 bytes (16 bits)? How many numbers can you represent
with four bytes?
Four bits: 16 combinations (0000, 0001, 0010, 0100, 1000, 0011, 0110, 1100, 0101,
1010, 1001, 0111, 1110, 1101, 1011, 1111)
Eight bits: 256 combinations
Two bytes/16 bits: 65,536 combinations
Four bytes/32 bits: 4,294,967,296 combinations
The “DOC” encoding was a unique encoding to Microsoft, while the “DOCX” encoding
is based on XML, the Extendable Markup Language. This makes it easier for other
programs to parse “DOCX” documents, along with conferring a number of other benefits
1.7 One of the powerful ideas in computer science is that encodings can be layered. Most
of the encodings we’ve talked about so far (e.g., pixels in a picture, characters, floating
point numbers) are based on binary. XML is a way of encoding information in text, which
is in turn encoded in binary. What are the advantages and disadvantages of using XML
rather than binary encodings?
Advantages:
-XML is easy for humans and computers to read.
-XML is easily extendible
-XML has been rapidly adopted by industry
Disadvantages:
-XML takes up more space than binary encoding
-XML is extendible and therefore not as standardized
(Source: http://www.mulberrytech.com/papers/HowAndWhyXML/slide009.html )
1.8 How can you encode a floating-point number in terms of bytes? Do a search on the
Web for “floating point.” You will find that there are different encodings of floating point
numbers. Take a common one like the IEEE Floating Point Standard as an example.
Assuming single precision, what is the largest and smallest numbers that you can
represent in that encoding?
A computer can represent a floating-point number as it would an integer number, but
with some extra information. Specifically, to be able to define the decimal portions of a
floating point, a computer must know an extra integer to raise 10 by to multiply the base
integer by. For example, if one was to represent the number 0.5 it would hold track of the
number 5 and -1, since 0.5 equals 5 x10^(-1).
(Source: http://www.wikipedia.org/wiki/IEEE_floating_point)
1.9 As we said in the chapter, computer science is about people. Start your exploration of
computer science by exploring the people who are computer scientists and influence
computer science. As you do, find Web sites that you believe are credible for your
information, and include the URL in your answers—with your reasons for believing that
source is credible. What general rules do you use to determine what is a credible Web
site?
Note: This question can be potentially confusing. Due to its structure, multiple
1.10 Look up Alan Kay, object-oriented programming, and the Dynabook on the Web.
Alan is one of the inspirations for the media computation approach that we use in this
book. Can you figure out what he has to do with media computation?
1.11 Look up Clarence (Skip) Ellis. Without him, Google Docs wouldn’t work the way
that they do to help people collaborate. What did he do?
1.12 Look up Grace Hopper on the Web. How did she contribute to programming
languages?
Grace Hopper created the first compiler for a computer programming language and
coined the term “debugging” for fixing computer flitches. (Source:
http://en.wikipedia.org/wiki/Grace_Hopper#cite_note-Booss03-6)
1.13 Look up Andrea Lawrence on the Web. What computer science department did she
chair?
1.14 Look up Alan Turing on the Web. What does he have to do with our notion of what
a computer can do and how encodings work?
Alan Turing created the definition for a modern computer in terms of what it can do,
referred to as a “Turing Machine”. Additionally, he came up with a means of encoding an
action table of a Turing machine as a string, such that someone can feed in instructions to
a machine and get an output back. (Source:
http://en.wikipedia.org/wiki/Universal_Turing_machine)
1.15 Look up Adele Goldberg on the Web. How did she contribute to programming
languages?
1.16 Look up Kurt Gödel on the Web. What amazing things did he do with encodings?
1.17 Look up Ada Lovelace on the Web. What amazing things did she do before the first
mechanical computer was built?
Ada Lovelace was the first ever computer programmer, before the first computer was
even built, having come up with a stepwise sequence of operations for solving
mathematical problems. (Source: http://www.computerhistory.org/babbage/adalovelace/)
1.18 Look up Claude Shannon on the Web. What did he do for his master’s thesis?
Claude Shannon proved in his master’s thesis that Boolean algebra could be used to
simplify relays used in the electromechanical phone exchanges of the day, and later
defined digital circuit design. (Source:
http://dspace.mit.edu/bitstream/handle/1721.1/11173/34541425.pdf?sequence=1)
1.19 Look up Richard Tapia on the Web. What has he done to encourage diversity in
computing?
Richard Tapia directed or co-directed more minority and women doctoral candidates in
science and engineering than anyone in the country and has lead numerous programs to
increase diversity in the fields of science and engineering. (Source:
http://tapiaconference.org/about/tapia)
She helped to create Google’s now famous unadorned search page, along with the look
and feel of some of the company’s most popular products. (Source:
http://dealbook.nytimes.com/2012/07/16/googles-marissa-mayer-tapped-as-yahoos-
chief/?hp)
1.21 Look up Shafi Goldwasser on the Web. What major computing prize did she win in
2012 and why?
The ACM Turing Award, which she won for work in the theoretic foundations for the
science cryptography and pioneered new ways to check mathematical proofs. (Source:
http://amturing.acm.org/award_winners/goldwasser_8627889.cfm)
1.22 Look up Mary Lou Jepsen on the Web. What new technology is she working on?
She is working on small screens that can seamlessly join together like legos to create
larger screens, along with wall screens. (Source:
http://www.fastcodesign.com/3036692/fast-feed/google-is-inventing-screens-that-snap-
together-like-lego)
1.23 Look up Ashley Qualls on the Web. What did she create that is worth a million
dollars?
She created a website as a teenager that offered free MySpace account designs, making
thousands of dollars from ad revenue alone. (Source:
https://web.archive.org/web/20080220145135/http://potw.news.yahoo.com/s/potw/52250
/teen-millionaire)
1.25 As in every field, people in computer science build on one another’s work.
. Who used the Logo Turtle to have fourth graders learn about fractions in mathematics?
Uri Wilensky authored NetLogo, which allows for simulation and modeling of ant
behavior and more. (Source: http://ccl.northwestern.edu/netlogo/index.shtml)
. One of the winners of the ACM Turing Award (the closest that computer science has to
a Nobel Prize) invented a computer system for typesetting books on a laser
printer. Who was that?
. The winner of a recent ACM Turing Award built a computer system on top of the last
typesetting system, to make it easier to use (but that’s not what he won the Turing
Award for). Who was that, and what did he win his award for?
Leslie Lamport developed the LaTeX system written on top of TeX. He won his
Turing Award in 2013 for contributions to distributed and concurrent systems,
essentially when several computations are executed simultaneously, potentially
interacting.
(Source: http://amturing.acm.org/award_winners/lamport_1205376.cfm)
Chapter 2
2.1
What is an algorithm?
Encoding: The means by which computers convert information into a particular form, for
example, from bytes to numbers to text. Note, the book does not contain an explicit
definition of encoding, but the two important things to get across are 1) the encoding’s
use in translating between different types of information and 2) tat the computer makes
use of multiple layers of encoding. (Chapter 1, Page 10)
2.2
Each image is composed of tiny dots called pixels, each composed of a sum of red, green,
and blue. The red, green, and blue values of a pixel are each represented as a byte; bytes
can then be represented as a number. (Pixel Information: Chapter 1, Pages 11-12; Byte
Information: Chapter 1, Pages 9-10)
Computers can represent text via ASCII (American Standard Code for Information
Interchange) encoding. Using this encoding, the number 65 is interpreted as the capital
letter A, 66 is interpreted as the capital letter B, and so on. Each individual character of a
piece of text can then become a collection of numbers. (Chapter 1, Page 10)
Remember that the computer can only represent integer numbers in raw binary. How can
computers represent floating-point (decimal) numbers?
2.3 What does def mean? What does the statement def someFunction(x,y): do?
The keyword “def” is used by Python to define new functions. The statement defines a
function with the title “someFunction” and the inputs “x” and “y”. The code directly after
this function header will be executed when the function is called. (Chapter 2, Page 34)
A local or global name could not be found. You need to define the function or variable
before you try to use it in any way.
2.5 What is the output from print 1 / 3? Why do you get this output?
0. You get this output as both 1 and 3 are assumed to be integer numbers by Python.
Since integer numbers only allow for whole numbers, the answer to “How many times
does 3 go into 1” is “0”.
2.6 What is the output from print 1.0 / 3? Why do you get this output?
0.3333333333333333. You get this output as Python recognized 1.0 as a floating point
number, meaning that it allows for a decimal number answer, the same you would get on
a calculator.
2.7 What is the output from print 10 + 3 * 7? Why do you get this output?
31. You get this output as Python follows the order of operations, such that multiplication
(3*7=21) occurs before addition (10+21).
2.8 What is the output from print (10 + 3) * 7? Why do you get this output?
91. You get this output as Python follows the order of operations, such that calculations
within parenthesis occur before multiplication.
2.9 What is the output from print "Hi" + "there"? Why do you get this output?
Hithere. You get this output as Python implements addition between str types (strings) by
concatenating the second str on to the first.
2.10 What is the output from print "Hi" + 10? Why do you get this output?
The error value is: cannot concatenate 'str' and 'int' objects
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means
that you did something such as trying to pass a string to a method that is expecting an
integer.
2.11 What is the output from print "Hi" * 10? Why do you get this output?
HiHiHiHiHiHiHiHiHiHi
You get this output as Python recognizes multiplying a str (string) by an int (integer) as a
desire to repeat that str the number of times represented by the int.
2.12 What is the output from print "Hi" + "there"? Why do you get this output?
2.13 What is the output from print "Hi" * "10"? Why do you get this output?
The error value is: can't multiply sequence by non-int of type 'str'
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means
that you did something such as trying to pass a string to a method that is expecting an
integer.
You get this output as Python has no standard way to multiply two str types (strings)
together.
2.14 What is the output from print "Hi" + "10"? Why do you get this output?
Hi10
You get this output as, while “10” may seem to be a number the symbol “ on both sides
indicate that is a str type variable (string). As such, python simply concatenates it to the
end of “Hi”.
2.15 What does show(p) do? (Hint: There’s more than one answer to this question.)
If p is defined as a variable, then Python will print to the console the value of p. If p has
no value, Python will print out:
A local or global name could not be found. You need to define the function or variable
before you try to use it in any way.
-15
-110
-2
-16
Mark