Book description
What will you learn from this book?
It’s no secret the world around you is becoming more connected, more configurable, more programmable, more computational. You can remain a passive participant, or you can learn to code. With Head First Learn to Code you’ll learn how to think computationally and how to write code to make your computer, mobile device, or anything with a CPU do things for you. Using the Python programming language, you’ll learn step by step the core concepts of programming as well as many fundamental topics from computer science, such as data structures, storage, abstraction, recursion, and modularity.
Why does this book look so different?
Based on the latest research in cognitive science and learning theory, Head First Learn to Code uses a visually rich format to engage your mind, rather than a text-heavy approach that puts you to sleep. Why waste your time struggling with new concepts? This multi-sensory learning experience is designed for the way your brain really works.
Publisher resources
Table of contents
- Praise for Head First Learn to Code
- Praise for other books by Eric Freeman
- Head First Learn to Code
- the author
-
how to use this book: Intro
- Who is this book for?
- We know what you’re thinking.
- Metacognition: thinking about thinking
- Here’s what WE did:
- Here’s what YOU can do to bend your brain into submission
-
Read Me
- We want you to learn the thinking process behind programming.
- In this book we use Python.
- We don’t exhaustively cover every aspect of the Python language.
- You can use a Mac or PC, or Linux for that matter.
- The activities are NOT optional.
- The redundancy is intentional and important.
- The examples are as lean as possible.
- The Brain Power exercises don’t usually have answers.
- Get the code examples, help, and discussion online.
- You’re going to have to install Python
- A word on organizing your code
- Acknowledgments*
- The Review Team
-
1. 1 thinking computationally: Getting Started
- Breaking it down
- How coding works
- Are we even speaking the same language?
- The world of programming languages
- How you’ll write and run code with Python
- A very brief history of Python
- Putting Python through its paces
- Saving your work
- Congrats on coding your first Python program!
- Phrase-O-Matic
- Getting the code in the machine
-
2. 2 simple values, variables, and types: Know Your Value
- Coding the Dog Age Calculator
- Going from pseudocode to code
- Step 1: Getting some input
- How the input function works
- Using variables to remember and store values
- Assigning the user’s input to a variable
- Step 2: Getting more input
- It’s time to run some code
- Getting some code entered
- A deep dive on variables
- Adding some expression
- Variables are called VARY-ables for a reason
- Better living through operator precedence
- Computing with operator precedence
- Crack the Code Challenge
- Back away from that keyboard!
- Step 3: Computing the dog’s age
- Houston, we’ve got a problem!
- To err is human to code
- A little more debugging...
- What are Python types, anyway?
- Fixing our code
- Houston, we have liftoff
- Step 4: User-friendly output
- Crack the Code Challenge SOLUTION
-
3. 3 booleans, decisions, and loops: Decisive Code
- Would you like to play a game?
- First, a high-level design
- The computer’s choice
- How to use the random number
- Taking things further...
- True? Or False?
- Introducing the Boolean type
- Making decisions
- Decisions and more decisions
- Back to Rock, Paper, Scissors
- Getting the user’s choice
- Taking a look at the user’s choice
- Adding the code to detect a tie
- Who won?
- How to implement the game logic
- More about Boolean operators
- Display the winner
- Got documentation?
- How to add comments to your code
- We need to finish that game!
- How do we know if the user’s choice is invalid?
- Checking out and cleaning up the expression
- How to continually prompt the user
- Doing things more than once
- How the while loop works
- How to use while to prompt the user until you get a valid choice
- Congratulations on coding your first game!
-
4. 4 lists and iteration: Providing Some Structure
- Can you help Bubbles-R-Us?
- How to represent multiple values in Python
- How lists work
- How big is that list, anyway?
- Accessing the last item in the list
- Python makes this even easier
- Using Python’s negative indices
- Meanwhile, back at Bubbles-R-Us...
- Cubicle conversation
- How to iterate over a list
- Fixing the output glitch
- Really fixing the output glitch
- The for loop, the preferred way to iterate over a list
- How the for loop works on a range of numbers
- Doing more with ranges
- Putting it all together
- Test drive the bubble report
- Cubicle conversation continued...
- Building your own list, from scratch
- Doing even more with lists
- Test drive the final report
- And the winners are...
- Testing the most cost-effective solution
-
5. 5 functions and abstraction: Getting Functional
- What’s wrong with the code, anyway?
- Turning a block of code into a FUNCTION
- We created a function, so how do we use it?
- But how does all this actually work?
- Functions can RETURN things too
- How to call a function that has a return value
- Getting a little refactoring under our belts
- Running the code
- How to abstract the avatar code
- Writing the get attribute function body
- Calling get attribute
- Let’s talk about variables a little more...
- Understanding variable scope
- When variables get passed to functions
- Making the drink_me function call
- What about using global variables in functions?
- Going further with parameters: default values and keywords
- How default parameter values work
- Always list your required parameters first!
- Using arguments with keywords
- How to think about all these options
- 6. 4, part 2, sorting and nested iteration: Putting Some Order in Your Data
-
7. 6 text, strings, and heuristics: Putting It All Together
- Welcome to the data sciences
- How do you compute something like readability?
- The game plan
- Writing some pseudocode
- We need some text to analyze
- Setting up the function
- First up: we need the total number of words in our text
- Cubicle conversation
- Computing the total number of sentences
- Writing the count_sentences function
- Computing the number of syllables, or, learning to love heuristics
- Cubicle conversation continued...
- Setting up the heuristic
- Writing the heuristic
- How to count vowels
- Ignoring consecutive vowels
- Writing the code to ignore consecutive vowels
- Removing final e’s, y’s, and punctuation
- Putting slicing (substrings) to work
- Finishing off the heuristic code
- Implementing the reading ease formula
- Taking it even further
-
8. 7 modules, methods, classes, and objects: Getting Modular
- Cubicle conversation
- A quick module review
- Cubicle conversation continued...
- The name global variable
- Cubicle conversation continued...
- Updating analyze.py
- Using analyze.py as a module
- Adding docstrings to analyze.py
- Exploring other Python modules
- Wait, did someone say “turtles”?!
- Creating your very own turtle
- Turtle lab
- Adding a second turtle
- What are turtles, anyway?
- What are objects?
- Okay, what’s a class then?
- A class tells us what an object knows and what an object can do
- How to use objects and classes
- What about those methods and attributes?
- Seeing classes and objects everywhere
- Get ready for some turtle races
- Planning the game
- Let’s start coding
- Setting up the game
- Writing the setup code
- Not so fast!
- Starting the race
- Don’t worry, this isn’t the end of objects.
- Mod coding cross
- Mod cross Solution
-
9. 8 recursion and dictionaries: Beyond Iteration and Indices
- A different way to compute
- And now the different way...
- Now let’s write some code for our two cases
- Let’s get some more practice
- Using recursion to detect palindromes
- Writing a recursive palindrome detector
- The Anti-Social Network
- Introducing the dictionary
- Let’s see how to create a dictionary
- And then add items
- And then retrieve values by their keys
- Keys and values do not have to be strings
- Of course you can remove keys as well
- But you might want to test to see if it exists first
- What about iterating through a dictionary?
- Okay, but can we get literal for a sec?
- Leveraging dictionaries at the Anti-Social Network
- But how do we add more attributes?
- Remember the Anti-Social Network’s killer feature?
- Finding the most anti-social user
- Now, it’s all you!
- Can we just remember function call results?
- Using a dictionary to remember our Fibonacci results
- We might as well use the $5 words: memoization
- Some more brain building
- A closer look at the koch function
- Truly exploring the koch fractal
- They don’t call it the Koch snowflake for nothin’
-
10. 9 saving and retrieving files: Persistence
- Ready for some Crazy Libs?
- How Crazy Libs is going to work
- Step 1: Read the text of the story from a file
- To read a file in Python, you first have to open it
- How to use file paths
- Relative paths
- Absolute paths
- Oh, and don’t forget to clean up when you’re done!
- Reading a file into your Python code
- Using the file object to read a file
- Oh, give it a break already...
- Hey, we’ve got a Crazy Lib game to finish!
- Using the readline method of the file object
- How do we know when we’ve read the last line?
- Ah, but there’s a easier way using the power of Python sequences
- Reading in a Crazy Lib template
- Processing the template text
- Now let’s process the text
- Using a new string method to fix the bug
- Actually fixing the bug
- Some code has real problems
- Handling exceptions
- Explicitly handling exceptions
- Updating Crazy Libs to handle exceptions
- Our last step: storing the Crazy Lib
- Updating the rest of the code
- File i/o cross Solution
-
11. 10 using web apis: You Really Should Get Out More
- Extending your reach with Web APIs
- How Web APIs work
- All Web APIs have a web address
- Time for a quick upgrade
- Doing the upgrade
- All we need now is a good Web API...
- A closer look at the API
- Web APIs provide data using JSON
- Now let’s look at that request module again
- Putting it all together: making a request to Open Notify
- How to use JSON in Python
- Using the JSON module on our ISS data
- Let’s add some graphics
- Meet the screen object
- Let’s add a turtle to represent the ISS
- Turtles can look like space stations too
- Forget the ISS—where are we?
- Finishing off the ISS code
-
12. 11 widgets, events, and emergent behavior: Getting Interactive
- A closer look at the Game of Life
- What we’re going to build
- Do we have the right design?
- How we’re going to build the simulator
- Building the data model
- Representing the grid
- Computing a generation of the Game of Life
- Computing each cell’s fate
- Completing the model code
- Where are we?
- Building the view
- Creating your first widget
- Adding the rest of the widgets
- Correcting the layout
- Placing the widgets into a grid layout
- Translating the grid layout to code
- Moving on to the controller
- Adding an update function
- Ready for another new style of computation?
- Let’s add a click handler
- How the start/pause button is going to work
- Implementing the start/pause button
- Another kind of event
- We have the technology: the after method
- Are we there yet?
- How to enter and edit cells directly
- Writing the grid_view handler
- Now it’s time to add some patterns
- Writing a handler for the OptionMenu
- How to define your patterns
- Writing the pattern loader
-
13. 12 object-oriented programming: A Trip to Objectville
- Breaking it down, a different way
- What’s the point of object-oriented programming, anyway?
- Designing your first class
- Writing your first class
- How the constructor works
- Writing the bark method
- How methods work
- Adding some inheritance
- Implementing the ServiceDog class
- A closer look at subclassing
- A ServiceDog IS-A Dog
- Testing IS-A in code
- How would you describe yourself?
- Overriding and extending behavior
- Welcome to Jargon City
- Object can HAS-Another object
- Designing a Doggie Hotel
- Implementing the Doggie Hotel
- Renovating the Doggie Hotel
- Adding some hotel activities
- I can do anything you can, or Polymorphism
- It’s about time we teach the other dogs to walk
- The power of inheritance
- Creating a Doggie Hotel walking service
- How are we going to hire a person to walk our dogs if we don’t even have people objects?
- A. appendix: leftovers: The Top Ten Topics (We Didn’t Cover)
- B. Bring your brain over to wickedlysmart.com
- Index
Product information
- Title: Head First Learn to Code
- Author(s):
- Release date: January 2018
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491958865
You might also like
book
Learn to Code by Solving Problems
Computers are capable of solving almost any problem when given the right instructions. That’s where programming …
book
Head First Design Patterns, 2nd Edition
What will you learn from this book? You know you don't want to reinvent the wheel, …
book
Head First Design Patterns
What’s so special about design patterns? At any given moment, someone struggles with the same software …
book
Head First Software Architecture
What will you learn from this book? If you're a software developer looking for a quick …