n
Solution and Answer Guide For All Chapters
k k k k k k
LAMBERT, FUNDAMENTALS OF PYTHON: FIRST PROGRAMS, 3E, CY24, 9780357881019; CHAPTER 1, INTR
K K K K K K K K K K K
ODUCTION
TABLE OF CONTENTS K K
ExercisekSolutions ........................................................................................................................................ 1
Exercisek1.1 ............................................................................................................................................... 1
Exercisek1.2 ............................................................................................................................................... 2
Exercisek1.3 ............................................................................................................................................... 3
ReviewkQuestionskAnswers ......................................................................................................................... 4
ProgrammingkExerciseskSolutions ............................................................................................................. 8
DebuggingkExerciseskSolutions ................................................................................................................... 8
EXERCISE SOLUTIONS K
EXERCISE 1.1 K
1. Listkthreekcommonktypeskofkcomputingkagents.
Solution:
Humankbeings,kdesktopkcomputers,kcellkphones
2. Writekankalgorithmkthatkdescribesktheksecondkpartkofkthekprocesskofkmakingkchangek(countingkoutkthekcoins
kandkbills).
Solution:
Therekarekvariouskwaysktokdokthis,kbutkherekiskone:
Repeat
Selectktheklargestkunitkofkmoneykthatkisklesskthankorkequalktokthekremainingkchange
kSubtractkthiskunitkfromkthekremainingkchange
Untilkthekremainingkchangekisk0
Thekcollectionkofkunitskselectedkrepresentkthekchange
3. Writekankalgorithmkthatkdescribeskakcommonktask,ksuchkaskbakingkakcake.
©k2024kCengage.kAllkRightskReserved.kMayknotkbekscanned,kcopiedkorkduplicated,korkpostedktokakpubliclykaccessib 1
le
website,kinkwholekorkinkpart.
,SolutionkandkAnswerkGuidekForkAllkChapters:kLambert,kFundamentalskofkPython:kFirstkPrograms,k3e,kCY24,k9780357881019;kChapterk1,kIntroductio
n
Solution:
Therekarekvariouskwaysktokdokthis,kbutkherekiskone:
Preheatkankovenktok375kdegrees
Addk1kcupkofkwaterkandk1keggktokakmixingkbowl
BeatkthekliquidkmixturekinkthekbowlkuntilkthekingredientskarekblendedkAd
dkthekcontentskofkakboxedkcakekmixktokthekmixingkbowl
Beatkthekmixturekinkthekbowlkuntilkthekingredientskarekblended
Pourkthekcontentskofkthekmixingkbowlkintokaklightlykgreasedkcakekpank
Bakekthekcakekinkthekovenkfork45kminutes
4. Describekankinstructionkthatkisknotkwellkdefinedkandkthuskcouldknotkbekincludedkaskakstepkinkankalgorithm.
kGivekankexamplekofksuchkankinstruction.
Solution:
Attemptingktokdividekaknumberkbyk0
5. Inkwhatksensekiskaklaptopkcomputerkakgeneral-purposekproblem-solvingkmachine?
Solution:
Aklaptopkcomputerkiskakgeneral-purposekproblem-
solvingkmachinekbecausekitkiskprogrammablekandkcanksolvekanykproblemkforkwhichktherekiskankalgorithm.
6. Listkfourkdeviceskthatkusekcomputerskandkdescribekthekinformationkthatktheykprocess.k(Hint:kThinkkofkthek
inputskandkoutputskofkthekdevices.)
Solution:
Digitalkcamera—images,kmusickplayer—sound,kcellkphone—text,kATM—numbers
EXERCISE 1.2 K
1. Listktwokexampleskofkinputkdeviceskandktwokexampleskofkoutputkdevices.
Solution:
Inputkdevices—keyboardkandkmouse,koutputkdevices—monitorkandkspeakers
2. Whatkdoeskthekcentralkprocessingkunitk(CPU)kdo?
Solution:
ThekCPUkfetches,kdecodes,kandkexecuteskinstructions.
3. Howkiskinformationkrepresentedkinkhardwarekmemory?
Solution:
Informationkiskrepresentedkusingkbinaryknotation,kwhichkinkhardwarekiskakpatternkofkvoltageklevels.
©k2024kCengage.kAllkRightskReserved.kMayknotkbekscanned,kcopiedkorkduplicated,korkpostedktokakpubliclykaccessib 2
le
website,kinkwholekorkinkpart.
,SolutionkandkAnswerkGuidekForkAllkChapters:kLambert,kFundamentalskofkPython:kFirstkPrograms,k3e,kCY24,k9780357881019;kChapterk1,kIntroductio
n
4. Whatkiskthekdifferencekbetweenkakterminal-basedkinterfacekandkakgraphicalkuserkinterface?
Solution:
Akterminal-
basedkinterfaceksupportskonlykthekinputkandkoutputkofktextkwithkakkeyboardkandkmonitor.kAkgraphicalkuserkint
erfaceksupportskthekoutputkofkimageskandkthekmanipulationkofkthemkwithkakpointingkdevice,kthekmouse.
5. Whatkrolekdoktranslatorskplaykinkthekprogrammingkprocess?
Solution:
Aktranslatorkconvertskakprogramkwrittenkinkakhigh-
levelklanguagek(humankreadablekandkwritable)ktokankequivalentkprogramkinkaklow-
levelklanguagek(machinekreadablekandkexecutable).
EXERCISE 1.3 K
1. Describekwhatkhappenskwhenkthekprogrammerkenterskthekstringk"Greetings!"kinkthekPythonkshell.
Solution:
Pythonkreadskthekstringk"Greetings!",kevaluateskit,kandkdisplayskthiskstringk(includingksinglekquotes)ki
nkthekshell.
2. Writekaklinekofkcodekthatkpromptskthekuserkforktheirknamekandksaveskthekuser’skinputkinkakvariablekcalled
name.
Solution:
namek=kinput("Enterkyourkname:k")
3. WhatkiskakPythonkscript?
Solution:
AkPythonkscriptkiskakcompletekPythonkprogramkthatkcankbekrunkfromkakcomputer’skoperatingksystem.
4. ExplainkwhatkgoeskonkbehindktheksceneskwhenkyourkcomputerkrunskakPythonkprogram.
Solution:
Ifkthekprogramkhasknotkalreadykbeenktranslated,kPython’skcompilerktranslateskitktokbytekcode.kThekPythonkvir
tualkmachinekthenkexecuteskthiskcode.
©k2024kCengage.kAllkRightskReserved.kMayknotkbekscanned,kcopiedkorkduplicated,korkpostedktokakpubliclykaccessib 3
le
website,kinkwholekorkinkpart.
, SolutionkandkAnswerkGuidekForkAllkChapters:kLambert,kFundamentalskofkPython:kFirstkPrograms,k3e,kCY24,k9780357881019;kChapterk1,kIntroductio
n
REVIEW QUESTIONS ANSWERS
K K
1. Whichkofkthekfollowingkiskank examplekofkankalgorithm?
a. Akdictionary
b. Akrecipe
c. Akshoppingklist
d. Thekspellingkcheckerkofkakwordkprocessor
Answer:kb
Feedback:
a. Incorrect.kAkdictionarykiskakdatakstructure.
b. Correct.kAkrecipekiskaksetkofkinstructionskthatkdescribeskakprocesskthatkhaltskwithkaksolutionktokakproblem.
c. Incorrect.kAkshoppingklistkiskakdatakstructure.
d. Incorrect.k Akwordkprocessorkiskakprogramkthatkconsistskofkinstructionskandkdata.
2. Whichkofkthekfollowingkcontainskinformation?
a. AnkaudiokCD
b. Akrefrigerator
c. Ankautomobile
d. Akstereokspeaker
k Answer:kakFeedbac
k:
a. Correct.kThekinformationkonkankaudiokCDkrepresentsksound.
b. Incorrect.kAkrefrigeratorkcontainskjustkfood,kifkit’sknotkempty.
c. Incorrect.kAnkautomobilekcontainskaksteeringkwheel,kengine,kexhaustkpipe,kandksokon.
d. Incorrect.kAkstereokspeakerkcontainskakmagnetickcoil,kwires,kandksokon.
3. Whichkofkthekfollowingkiskakgeneral-purposekcomputingkdevice?
a. Aksmartphone
b. Akportablekmusickplayer
c. Akmicrowavekoven
d. Akprogrammablekthermostat
©k2024kCengage.kAllkRightskReserved.kMayknotkbekscanned,kcopiedkorkduplicated,korkpostedktokakpubliclykaccessib 4
le
website,kinkwholekorkinkpart.