Instructor Solutions Manual (Page 1 of 212)
INSTRUCTOR
SOLUTIONS
MANUAL
to accompany An Introduction to Programming Using Python
by David I. Schneider
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.Download Link at the end of this File 1 / 4
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. 2 / 4
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.
- 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
- print((7 * 8) + 5) 26. (1 + (2 * 9)) **3
- print(.055 * 20) 28. 15 – (3 * (2 + (3 ** 4)))
- 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.
4
- 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
- cost += 5 56. sum *= 2 57. cost /= 6 58. sum - = 7
- sum %= 2 60. cost //= 3 © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. 3 / 4
Instructor Solutions Manual (Page 4 of 212)
- revenue = 98456
costs = 45000 profit = revenue - costs print(profit)
- costPerShare = 25.625
numberOfShares = 400 amount = costPerShare * numberOfShares print(amount)
- price = 19.95
discountPercent = 30 markdown = (discountPercent / 100) * price price - = markdown print(round(price, 2))
- fixedCosts = 5000
pricePerUnit = 8 costPerUnit = 6 breakEvenPoint = fixedCosts / (pricePerUnit – costPerUnit) print(breakEvenPoint)
- balance = 100
balance += 0.05 * balance balance += 0.05 * balance balance += 0.05 * balance print(round(balance, 2))
- balance = 100
balance = ((1.05) * balance) + 100 balance = ((1.05) * balance) + 100 balance *= 1.05 print(round(balance, 2))
- balance = 100
balance *= 1.05 ** 10 print(round(balance, 2))
- purchasePrice = 10
sellingPrice = 15 percentProfit = 100 * ((sellingPrice – purchasePrice) / purchasePrice) print(percentProfit)
- tonsPerAcre = 18
acres = 30 totalTonsProduced = tonsPerAcre * acres print(totalTonsProduced )
- initialVelocity = 50
- / 4
initialHeight = 5 t = 3 height = (-16 * (t ** 2)) + (initialVelocity * t) + initialHeight print(height) © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.