Page 10 - Python Basics: A Practical Introduction to Python 3
P. 10
Contents
4.3 Manipulate Strings With Methods . . . . . . . . . . 79
4.4 Interact With User Input . . . . . . . . . . . . . . . 85
4.5 Challenge: Pick Apart Your User’s Input . . . . . . . 88
4.6 Working With Strings and Numbers . . . . . . . . . 88
4.7 Streamline Your Print Statements . . . . . . . . . . 94
4.8 Find a String in a String . . . . . . . . . . . . . . . . 96
4.9 Challenge: Turn Your User Into a L33t H4x0r . . . . 99
4.10 Summary and Additional Resources . . . . . . . . . 100
5 Numbers and Math 102
5.1 Integers and Floating-Point Numbers . . . . . . . . 103
5.2 Arithmetic Operators and Expressions . . . . . . . . 107
5.3 Challenge: Perform Calculations on User Input . . . 115
5.4 Make Python Lie to You . . . . . . . . . . . . . . . . 116
5.5 Math Functions and Number Methods . . . . . . . . 118
5.6 Print Numbers in Style . . . . . . . . . . . . . . . . 123
5.7 Complex Numbers . . . . . . . . . . . . . . . . . . 126
5.8 Summary and Additional Resources . . . . . . . . . 130
6 Functions and Loops 132
6.1 What Is a Function, Really? . . . . . . . . . . . . . . 133
6.2 Write Your Own Functions . . . . . . . . . . . . . . 137
6.3 Challenge: Convert Temperatures . . . . . . . . . . 146
6.4 Run in Circles . . . . . . . . . . . . . . . . . . . . . 147
6.5 Challenge: Track Your Investments . . . . . . . . . . 156
6.6 Understand Scope in Python . . . . . . . . . . . . . 157
6.7 Summary and Additional Resources . . . . . . . . . 162
7 Finding and Fixing Code Bugs 164
7.1 Use the Debug Control Window . . . . . . . . . . . 165
7.2 Squash Some Bugs . . . . . . . . . . . . . . . . . . 171
7.3 Summary and Additional Resources . . . . . . . . . 179
8 Conditional Logic and Control Flow 181
8.1 Compare Values . . . . . . . . . . . . . . . . . . . . 182
8.2 Add Some Logic . . . . . . . . . . . . . . . . . . . . 186
8.3 Control the Flow of Your Program . . . . . . . . . . 194
9