1
Introduction to Computers
and Python
Objectives
In this chapter you’ll:
Understand the strengths of
Python and other leading
programming languages.
Understand the importance of
libraries.
Notebook for executing
Python code.
Learn how big “big data” is
and how quickly it’s getting
even bigger.
PyCDS_01_Intro.fm Page 1 Tuesday, May 21, 2019 11:07 AM
2Introduction to Computers and Python
Note: Throughout the Instructor Solutions Manual, solutions are not provided for project,
research and challenge exercises—many of which are substantial and appropriate for term
projects, directed-study projects, capstone-course projects and thesis topics. Before assign
ing a particular exercise for homework, instructors should check the IRC to be sure the
Exercises
1.1 (IPython Session) Using the techniques you learned in Section 1.10.1, execute the
following expressions. Which, if any, produce a runtime error?
a) 10 / 3
b) 10 // 3
c) 10 / 0
d) 10 // 0
e) 0 / 10
f) 0 // 10
Answer: (c) and (d) produce ZeroDivisionErrors because division-by-zero is not
allowed in Python.
1.2 (IPython Session) Using the techniques you learned in Section 1.10.1, execute the
following expressions. Which, if any, produce a runtime error?
a) 10 / 3 + 7
b) 10 // 3 + 7
c) 10 / (3 + 7)
d) 10 / 3 – 3
e) 10 / (3 – 3)
f) 10 // (3 – 3)
1.3 (Creating a Jupyter Notebook) Using the techniques you learned in Section 1.10.3,
create a Jupyter Notebook containing cells for the previous exercise’s expressions and exe-
cute those expressions.
1.4 (Computer Organization) Fill in the blanks in each of the following statements:
a) The logical unit that receives information from outside the computer for use by
the computer is the .
b) is a logical unit that sends information which has already been processed
by the computer to various devices so that it may be used outside the computer.
Answer: The output unit.
c) and are logical units of the computer that retain information.
PyCDS_01_Intro.fm Page 2 Tuesday, May 21, 2019 11:07 AM
Exercises 3
d) is a logical unit of the computer that performs calculations.
e) is a logical unit of the computer that makes logical decisions.
f) is a logical unit of the computer that coordinates the activities of all
the other logical units.
1.5 (Clock as an Object) Clocks are among the world’s most common objects. Discuss
how each of the following terms and concepts applies to the notion of a clock: class, object,
instantiation, instance variable, reuse, method, inheritance (consider, for example, an
alarm clock), superclass, subclass.
Answer: Class—A class Clock would define the instance variables and methods
that represent a clock’s data and functionality. A clock’s instance variables (at-
tributes) might store the clock’s time, style (digital or analog), etc. The behav-
1.6 (Gender Neutrality) Write down the steps of a manual procedure for processing a
paragraph of text and replacing gender-specific words with gender-neutral ones. Assuming
that you’ve been given a list of gender-specific words and their gender-neutral replace-
ments (for example, replace “wife” or “husband” with “spouse,” replace “man” or “wom-
an” with “person,” replace “daughter” or “son” with “child,” and so on), explain the
procedure you’d use to read through a paragraph of text and manually perform these re-
placements. How might your procedure generate a strange term like “woperchild” and
how might you modify your procedure to avoid this possibility? In Chapter 3, you’ll learn
that a more formal computing term for “procedure” is “algorithm,” and that an algorithm
specifies the steps to be performed and the order in which to perform them.
Answer: Search through the entire paragraph for a word such as “wife” and replace
4Introduction to Computers and Python
PyCDS_01_Intro.fm Page 4 Tuesday, May 21, 2019 11:07 AM