Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
,Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
TABLE OF CONTENTS HC HC
Exercise Solutions........................................................................................................................................ 1
hc
Exercise 1.1 ............................................................................................................................................... 1
hc
Exercise 1.2 ............................................................................................................................................... 2
hc
Exercise 1.3 ............................................................................................................................................... 3
hc
Review Questions Answers ......................................................................................................................... 4
hc hc
Programming Exercises Solutions ............................................................................................................. 8
hc hc
Debugging Exercises Solutions ................................................................................................................... 8
hc hc
EXERCISE SOLUTIONS HC
EXERCISE 1.1 HC
1. List three common types of computing agents.
hc hc hc hc hc hc
Solution:
Human beings, desktop computers, cell phones
hc hc hc hc hc
2. Write an algorithm that describes the second part of the process of making change (counting out the coins
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
and bills).
hc hc
Solution:
There are various ways to do this, but here is one:
hc hc hc hc hc hc hc hc hc hc
Repeat
Select the largest unit of money that is less than or equal to the remaining change
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc h
Subtract this unit from the remaining change
c hc hc hc hc hc hc
Until the remaining change is 0
hc hc hc hc hc
The collection of units selected represent the change
hc hc hc hc hc hc hc
3. Write an algorithm that describes a common task, such as baking a cake.
hc hc hc hc hc hc hc hc hc hc hc hc
,Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
There are various ways to do this, but here is one:
hc hc hc hc hc hc hc hc hc hc
Preheat an oven to 375 degrees hc hc hc hc hc
Add 1 cup of water and 1 egg to a mixing bowl
hc hc hc hc hc hc hc hc hc hc hc
Beat the liquid mixture in the bowl until the ingredients are blended A
hc hc hc hc hc hc hc hc hc hc hc hc
dd the contents of a boxed cake mix to the mixing bowl
hc hc hc hc hc hc hc hc hc hc hc
Beat the mixture in the bowl until the ingredients are blended
hc hc hc hc hc hc hc hc hc hc
Pour the contents of the mixing bowl into a lightly greased cake pan
hc hc hc hc hc hc hc hc hc hc hc hc hc
Bake the cake in the oven for 45 minutes
hc hc hc hc hc hc hc hc
4. Describe an instruction that is not well defined and thus could not be included as a step in an algorithm.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
Give an example of such an instruction.
hc hc hc hc hc hc hc
Solution:
Attempting to divide a number by 0 hc hc hc hc hc hc
5. In what sense is a laptop computer a general-purpose problem-solving machine?
hc hc hc hc hc hc hc hc hc hc
Solution:
A laptop computer is a general-purpose problem-
hc hc hc hc hc hc
solving machine because it is programmable and can solve any problem for which there is an algorithm.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
6. List four devices that use computers and describe the information that they process. (Hint: Think of th
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
e inputs and outputs of the devices.)
hc hc hc hc hc hc
Solution:
Digital camera—images, music player—sound, cell phone—text, ATM—numbers
hc hc hc hc hc hc
EXERCISE 1.2 HC
1. List two examples of input devices and two examples of output devices.
hc hc hc hc hc hc hc hc hc hc hc
Solution:
Input devices—keyboard and mouse, output devices—monitor and speakers
hc hc hc hc hc hc hc
2. What does the central processing unit (CPU) do?
hc hc hc hc hc hc hc
Solution:
The CPU fetches, decodes, and executes instructions.
hc hc hc hc hc hc
3. How is information represented in hardware memory?
hc hc hc hc hc hc
Solution:
Information is represented using binary notation, which in hardware is a pattern of voltage levels.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc
, Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
4. What is the difference between a terminal-based interface and a graphical user interface?
hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
A terminal-
hc
based interface supports only the input and output of text with a keyboard and monitor. A graphical user i
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
nterface supports the output of images and the manipulation of them with a pointing device, the mouse.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
5. What role do translators play in the programming process?
hc hc hc hc hc hc hc hc
Solution:
A translator converts a program written in a high-
hc hc hc hc hc hc hc hc
level language (human readable and writable) to an equivalent program in a low-
hc hc hc hc hc hc hc hc hc hc hc hc
level language (machine readable and executable).
hc hc hc hc hc
EXERCISE 1.3 HC
1. Describe what happens when the programmer enters the string "Greetings!" in the Python shell.
hc hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
Python reads the string "Greetings!", evaluates it, and displays this string (including single quotes)
hc hc hc hc hc hc hc hc hc hc hc hc hc hc
in the shell.
hc hc
2. Write a line of code that prompts the user for their name and saves the user’s input in a variable called
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
name.
Solution:
name= input("Enter your name: ")
c
h hc hc hc hc
3. What is a Python script?
hc hc hc hc
Solution:
A Python script is a complete Python program that can be run from a computer’s operating system.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
4. Explain what goes on behind the scenes when your computer runs a Python program.
hc hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
If the program has not already been translated, Python’s compiler translates it to byte code. The Python vir
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
tual machine then executes this code.
hc hc hc hc hc
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
,Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
TABLE OF CONTENTS HC HC
Exercise Solutions........................................................................................................................................ 1
hc
Exercise 1.1 ............................................................................................................................................... 1
hc
Exercise 1.2 ............................................................................................................................................... 2
hc
Exercise 1.3 ............................................................................................................................................... 3
hc
Review Questions Answers ......................................................................................................................... 4
hc hc
Programming Exercises Solutions ............................................................................................................. 8
hc hc
Debugging Exercises Solutions ................................................................................................................... 8
hc hc
EXERCISE SOLUTIONS HC
EXERCISE 1.1 HC
1. List three common types of computing agents.
hc hc hc hc hc hc
Solution:
Human beings, desktop computers, cell phones
hc hc hc hc hc
2. Write an algorithm that describes the second part of the process of making change (counting out the coins
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
and bills).
hc hc
Solution:
There are various ways to do this, but here is one:
hc hc hc hc hc hc hc hc hc hc
Repeat
Select the largest unit of money that is less than or equal to the remaining change
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc h
Subtract this unit from the remaining change
c hc hc hc hc hc hc
Until the remaining change is 0
hc hc hc hc hc
The collection of units selected represent the change
hc hc hc hc hc hc hc
3. Write an algorithm that describes a common task, such as baking a cake.
hc hc hc hc hc hc hc hc hc hc hc hc
,Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
There are various ways to do this, but here is one:
hc hc hc hc hc hc hc hc hc hc
Preheat an oven to 375 degrees hc hc hc hc hc
Add 1 cup of water and 1 egg to a mixing bowl
hc hc hc hc hc hc hc hc hc hc hc
Beat the liquid mixture in the bowl until the ingredients are blended A
hc hc hc hc hc hc hc hc hc hc hc hc
dd the contents of a boxed cake mix to the mixing bowl
hc hc hc hc hc hc hc hc hc hc hc
Beat the mixture in the bowl until the ingredients are blended
hc hc hc hc hc hc hc hc hc hc
Pour the contents of the mixing bowl into a lightly greased cake pan
hc hc hc hc hc hc hc hc hc hc hc hc hc
Bake the cake in the oven for 45 minutes
hc hc hc hc hc hc hc hc
4. Describe an instruction that is not well defined and thus could not be included as a step in an algorithm.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
Give an example of such an instruction.
hc hc hc hc hc hc hc
Solution:
Attempting to divide a number by 0 hc hc hc hc hc hc
5. In what sense is a laptop computer a general-purpose problem-solving machine?
hc hc hc hc hc hc hc hc hc hc
Solution:
A laptop computer is a general-purpose problem-
hc hc hc hc hc hc
solving machine because it is programmable and can solve any problem for which there is an algorithm.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
6. List four devices that use computers and describe the information that they process. (Hint: Think of th
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
e inputs and outputs of the devices.)
hc hc hc hc hc hc
Solution:
Digital camera—images, music player—sound, cell phone—text, ATM—numbers
hc hc hc hc hc hc
EXERCISE 1.2 HC
1. List two examples of input devices and two examples of output devices.
hc hc hc hc hc hc hc hc hc hc hc
Solution:
Input devices—keyboard and mouse, output devices—monitor and speakers
hc hc hc hc hc hc hc
2. What does the central processing unit (CPU) do?
hc hc hc hc hc hc hc
Solution:
The CPU fetches, decodes, and executes instructions.
hc hc hc hc hc hc
3. How is information represented in hardware memory?
hc hc hc hc hc hc
Solution:
Information is represented using binary notation, which in hardware is a pattern of voltage levels.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc
, Solution and Answer Guide For All Chapters: Lambert, Fundamentals of Python: First Programs, 3e, CY24, 9780357881019; Chapter 1, Introduction
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
4. What is the difference between a terminal-based interface and a graphical user interface?
hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
A terminal-
hc
based interface supports only the input and output of text with a keyboard and monitor. A graphical user i
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
nterface supports the output of images and the manipulation of them with a pointing device, the mouse.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
5. What role do translators play in the programming process?
hc hc hc hc hc hc hc hc
Solution:
A translator converts a program written in a high-
hc hc hc hc hc hc hc hc
level language (human readable and writable) to an equivalent program in a low-
hc hc hc hc hc hc hc hc hc hc hc hc
level language (machine readable and executable).
hc hc hc hc hc
EXERCISE 1.3 HC
1. Describe what happens when the programmer enters the string "Greetings!" in the Python shell.
hc hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
Python reads the string "Greetings!", evaluates it, and displays this string (including single quotes)
hc hc hc hc hc hc hc hc hc hc hc hc hc hc
in the shell.
hc hc
2. Write a line of code that prompts the user for their name and saves the user’s input in a variable called
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
name.
Solution:
name= input("Enter your name: ")
c
h hc hc hc hc
3. What is a Python script?
hc hc hc hc
Solution:
A Python script is a complete Python program that can be run from a computer’s operating system.
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
4. Explain what goes on behind the scenes when your computer runs a Python program.
hc hc hc hc hc hc hc hc hc hc hc hc hc
Solution:
If the program has not already been translated, Python’s compiler translates it to byte code. The Python vir
hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc hc
tual machine then executes this code.
hc hc hc hc hc