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