z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Solution and Answer Guide For All Chapters z9 z9 z9 z9 z9 z9
LAMBERT, FUNDAMENTALS OF PYTHON: FIRST PROGRAMS, 3E, CY24, 9780357881019; CHAPTER 1,
Z9 Z 9 Z 9 Z9 Z 9 Z9 Z9 Z9 Z9 Z 9
INTRODUCTION
Z9
TABLE OF CONTENTS Z9 Z9
Exercise Solutions ...................................................................................................................................... 1
z9
Exercise 1.1 ............................................................................................................................................. 1
z9
Exercise 1.2 ............................................................................................................................................. 2
z9
Exercise 1.3 ............................................................................................................................................. 3
z9
Review Questions Answers........................................................................................................................ 4
z9 z9
Programming Exercises Solutions ............................................................................................................ 8
z9 z9
Debugging Exercises Solutions.................................................................................................................. 8
z9 z9
EXERCISE SOLUTIONS Z9
EXERCISE 1.1 Z9
1. List three common types of computing agents.
z9 z9 z9 z9 z9 z9
Solution:
Human beings, desktop computers, cell phones z9 z9 z9 z9 z9
2. Write an algorithm that describes the second part of the process of making change (counting out the coins
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
and bills).
z9 z9
Solution:
There are various ways to do this, but here is one:
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Repeat
Select the largest unit of money that is less than or equal to the remaining change
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Subtract this unit from the remaining change
z9 z9 z9 z9 z9 z9 z9
Until the remaining change is 0 z9 z9 z9 z9 z9
The collection of units selected represent the change
z9 z9 z9 z9 z9 z9 z9
3. Write an algorithm that describes a common task, such as baking a cake.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
© 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
1
website, in whole or in part.
z9 z9 z9 z9 z9
,Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Solution:
There are various ways to do this, but here is one:
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Preheat an oven to 375 degrees z9 z9 z9 z9 z9
Add 1 cup of water and 1 egg to a mixing bowl
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Beat the liquid mixture in the bowl until the ingredients are blended Add
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
the contents of a boxed cake mix to the mixing bowl
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Beat the mixture in the bowl until the ingredients are blended
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Pour the contents of the mixing bowl into a lightly greased cake pan
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Bake the cake in the oven for 45 minutes
z9 z9 z9 z9 z9 z9 z9 z9 z9
4. Describe an instruction that is not well defined and thus could not be included as a step in an algorithm.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Give an example of such an instruction.
z9 z9 z9 z9 z9 z9 z9
Solution:
Attempting to divide a number by 0 z9 z9 z9 z9 z9 z9
5. In what sense is a laptop computer a general-purpose problem-solving machine?
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Solution:
A laptop computer is a general-purpose problem-solving machine because it is programmable and can solve
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
any problem for which there is an algorithm.
z9 z9 z9 z9 z9 z9 z9 z9
6. List four devices that use computers and describe the information that they process. (Hint: Think of the
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
inputs and outputs of the devices.)
z9 z9 z9 z9 z9 z9
Solution:
Digital camera—images, music player—sound, cell phone—text, ATM—numbers
z9 z9 z9 z9 z9 z9
EXERCISE 1.2 Z9
1. List two examples of input devices and two examples of output devices.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Solution:
Input devices—keyboard and mouse, output devices—monitor and speakers
z9 z9 z9 z9 z9 z9 z9
2. What does the central processing unit (CPU) do?
z9 z9 z9 z9 z9 z9 z9
Solution:
The CPU fetches, decodes, and executes instructions.
z9 z9 z9 z9 z9 z9
3. How is information represented in hardware memory?
z9 z9 z9 z9 z9 z9
Solution:
Information is represented using binary notation, which in hardware is a pattern of voltage levels.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
© 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
2
website, in whole or in part.
z9 z9 z9 z9 z9
,Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
4. What is the difference between a terminal-based interface and a graphical user interface?
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Solution:
A terminal-based interface supports only the input and output of text with a keyboard and monitor. A
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
graphical user interface supports the output of images and the manipulation of them with a pointing device,
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
the mouse.
z9 z9
5. What role do translators play in the programming process?
z9 z9 z9 z9 z9 z9 z9 z9
Solution:
A translator converts a program written in a high-level language (human readable and writable) to an
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
equivalent program in a low-level language (machine readable and executable).
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
EXERCISE 1.3 Z9
1. Describe what happens when the programmer enters the string "Greetings!" in the Python shell.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Solution:
Python reads the string "Greetings!", evaluates it, and displays this string (including single quotes) in
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
the shell.
z9 z9
2. Write a line of code that prompts the user for their name and saves the user’s input in a variable called
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
name.
Solution:
name= input("Enter your name: ")
9
z z9 z9 z9 z9
3. What is a Python script?
z9 z9 z9 z9
Solution:
A Python script is a complete Python program that can be run from a computer’s operating system.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
4. Explain what goes on behind the scenes when your computer runs a Python program.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
Solution:
If the program has not already been translated, Python’s compiler translates it to byte code. The Python
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
virtual machine then executes this code.
z9 z9 z9 z9 z9 z9
© 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
3
website, in whole or in part.
z9 z9 z9 z9 z9
, Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
REVIEW QUESTIONS ANSWERS Z9 Z9
1. Which of the following is an example of an algorithm?
z9 z9 z9 z9 z9 z 9 z9 z9 z9
a. A dictionary
z9
b. A recipe
z9
c. A shopping list
z9 z9
d. The spelling checker of a word processor
z9 z9 z9 z9 z9 z9
Answer: b z9
Feedback:
a. Incorrect. A dictionary is a data structure. z9 z9 z9 z9 z9 z9
b. Correct. A recipe is a set of instructions that describes a process that halts with a solution to a problem.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
c. Incorrect. A shopping list is a data structure. z9 z9 z9 z9 z9 z9 z9
d. Incorrect. A word processor is a program that consists of instructions and data.
z 9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
2. Which of the following contains information?
z9 z9 z9 z9 z9
a. An audio CD z9 z9
b. A refrigerator
z9
c. An automobile z9
d. A stereo speaker
z9 z9
z9Answer: a z9
z9Feedback:
a. Correct. The information on an audio CD represents sound.
z9 z9 z9 z9 z9 z9 z9 z9
b. Incorrect. A refrigerator contains just food, if it’s not empty.z9 z9 z9 z9 z9 z9 z9 z9 z9
c. Incorrect. An automobile contains a steering wheel, engine, exhaust pipe, and so on.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
d. Incorrect. A stereo speaker contains a magnetic coil, wires, and so on.
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
3. Which of the following is a general-purpose computing device?
z9 z9 z9 z9 z9 z9 z9 z9
a. A smartphone
z9
b. A portable music player
z9 z9 z9
c. A microwave oven
z9 z9
d. A programmable thermostat
z9 z9
© 2024 Cengage. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible
z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9 z9
4
website, in whole or in part.
z9 z9 z9 z9 z9