Instructor Solutions Manual (Page 1 of 212)
INSTRUCTOR
SOLUTIONS
MANUAL
to accompany
An Introduction to Programming
Using Python
by David I. Schneider
Copyright © 2016 by Pearson Higher Education. All rights reserved.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Instructor Solutions Manual (Page 2 of 212)
CONTENTS
Chapter 2 Core Objects, Variables, Input, and Output
2.1 Numbers 3
2.2 Strings 5
2.3 Output 10
2.4 Lists, Tuples, and Files – an Introduction 13
Programming Projects Chapter 2 15
Chapter 3 Structures that Control Flow
3.1 Relational and Logical Operators 18
3.2 Decision Structures 18
3.3 The while Loop 24
3.4 The for Loop 30
Programming Projects Chapter 3 40
Chapter 4 Functions
4.1 Functions, Part 1 43
4.2 Functions, Part 2 50
Programming Projects Chapter 4 62
Chapter 5 Processing Data
5.1 Processing Data, Part 1 69
5.2 Processing Data, Part 2 75
5.3 Processing Data with Dictionaries 86
Programming Projects Chapter 5 95
Chapter 6 Miscellaneous Topics
6.1 Exception Handling 104
6.2 Selecting Random Values 106
6.3 Turtle Graphics 111
6.4 Recursion 130
Programming Projects Chapter 6 132
Chapter 7 Object-Oriented Programming
7.1 Classes and Objects 137
7.2 Inheritance 147
Programming Projects Chapter 7 154
Chapter 8 Graphical User Interface
8.1 Widgets 159
8.2 The Grid Geometry Manager 167
8.3 Writing GUI Programs 178
Programming Projects Chapter 8 207
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Instructor Solutions Manual (Page 3 of 212)
Answers
CHAPTER 2
EXERCISES 2.1
1. 12 2. 49 3. .125 4. 23 5. 8 6. -96 7. 2 8. 2
9. 1 10. 3 11. 1 12. 0 13. Not valid 14. Not valid
15. Valid 16. Not valid 17. Not valid 18. Not valid 19. 10
20. 14 21. 16 22. 16 23. 9 24. 8
25. print((7 * 8) + 5) 26. (1 + (2 * 9)) **3
27. print(.055 * 20) 28. 15 – (3 * (2 + (3 ** 4)))
29. print(17 * (3 + 162)) 30. (4 + (1 / 2)) – (3 + (5 / 8))
31.
x
y
x = 2
2
does not exist
y = 3 * x
2
6
x = y + 5
11
6
print(x + 4)
11
6
y = y + 1
11
7
32.
bal
inter
withDr
bal = 100
100
does not exist
does not exist
inter = .05
100
.05
does not exist
withDr = 25
100
.05
25
bal += (inter * bal)
105
.05
25
bal = bal - withDr
80
.05
33. 24 34. 1 8 9 35. 10 36. 225
37. 2 15 38. 5 10 39. The third line should read c = a + b.
40. 1,234 should not contain a comma; $100 should not have a dollar sign; Deposit should begin
with a lowercase letter d.
41. The first line should read interest = 0.05. 43. 10 45. 7 47. 3.128
49. -2 50. 2 51. 0 52. 1 53. 6 54. 1
55. cost += 5 56. sum *= 2 57. cost /= 6 58. sum -= 7
59. sum %= 2 60. cost //= 3
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Instructor Solutions Manual (Page 4 of 212)
61. revenue = 98456
costs = 45000
profit = revenue - costs
print(profit)
62. costPerShare = 25.625
numberOfShares = 400
amount = costPerShare * numberOfShares
print(amount)
63. price = 19.95
discountPercent = 30
markdown = (discountPercent / 100) * price
price -= markdown
print(round(price, 2))
64. fixedCosts = 5000
pricePerUnit = 8
costPerUnit = 6
breakEvenPoint = fixedCosts / (pricePerUnit – costPerUnit)
print(breakEvenPoint)
65. balance = 100
balance += 0.05 * balance
balance += 0.05 * balance
balance += 0.05 * balance
print(round(balance, 2))
66. balance = 100
balance = ((1.05) * balance) + 100
balance = ((1.05) * balance) + 100
balance *= 1.05
print(round(balance, 2))
67. balance = 100
balance *= 1.05 ** 10
print(round(balance, 2))
68. purchasePrice = 10
sellingPrice = 15
percentProfit = 100 * ((sellingPrice – purchasePrice) / purchasePrice)
print(percentProfit)
69. tonsPerAcre = 18
acres = 30
totalTonsProduced = tonsPerAcre * acres
print(totalTonsProduced)
70. initialVelocity = 50
initialHeight = 5
t = 3
height = (-16 * (t ** 2)) + (initialVelocity * t) + initialHeight
print(height)
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Instructor Solutions Manual (Page 5 of 212)
71. distance = 233
elapsedTime = 7 - 2
averageSpeed = distance / elapsedTime
print(averageSpeed)
72. miles = 23695 - 23352
gallonsUsed = 14
milesPerGallon = miles / gallonsUsed
print(milesPerGallon)
73. gallonsPerPersonDaily = 1600
numberOfPeople = 315000000
numberOfDays = 365
gallonsPerYear = gallonsPerPersonDaily * numberOfPeople * numberOfDays
print(gallonsPerYear)
74. pizzasPerSecond = 350
secondsInDay = 60 * 60 * 24
numPerDay = pizzasPerSecond * secondsInDay
print(numPerDay))
75. numberOfPizzarias = 70000
percentage = .12
numberOfRestaurants = numberOfPizzarias / percentage
print(round(numberOfRestaurants))
76. pop2000 = 281
pop2050 = 404
percentGrowth = round(100 * ((pop2050 - pop2000) / pop2000))
print(round(percentGrowth))
77. nationalDebt = 1.68e+13
population = 3.1588e+8
perCapitaDebt = nationalDebt / population
print(round(perCapitaDebt))
78. cubicFeet = (5280 ** 3)
caloriesPercubicFoot = 48600
totalNumberOfCalories = cubicFeet * caloriesPercubicFoot
print(totalNumberOfCalories))
EXERCISES 2.2
1. Python 2. Hello 3. Ernie 4. Bert 5. "o" 6. "o"
7. "h" 8. "n" 9. "Pyt" 10. [] 11. "Py" 12. "Thon"
13. "h" 14. "ytho" 15. "th" 16. "th" 17. "Python" 19. 2
20. -1 21. -1 23. 10 24. 3 25. 2 26. 5
27. -1 28. -1 29. 3 30. "BRRR" 31. 8 ball 32. 4
33. "8 BALL" 35. "hon" 37. "The Artist" 39. 5
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.