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