Home > Articles

Computer Programming and Python

Captain Code is a welcoming, engaging, and fun introduction to becoming a coder. This excerpt introduces what computer programming is and provides the steps for installing Python.

This chapter is from the book

Hello, and welcome. We love coding, and by the time you’re done with this book we think you will, too. We’re going to help you learn to code the way that we learned, by doing—no long lectures, no reading lots of instructions, and no drawn-out explanations. In every chapter you’ll get to do stuff, and you’ll learn while doing.

Except for this chapter, sorry. :-( Before you start developing your coding superpowers it’s really important to understand what coding actually is, so we’ll spend just a few minutes reviewing that. And then we’ll help you install the software you’ll need to get started. But, after that, it’s all doing. Promise.

Understanding Computer Programming

Let’s start by taking a few minutes to understand what computer programming actually is, and to do that we need to talk about computers.

What is a computer?

You’ve seen computers, and they are all basically the same; they have screens, a keyboard, mouse or touchpad, and some fold in half, like a notebook. Right? No, wrong! The truth is that most of the computers that you’ve seen and used look nothing at all like that. Really.

For example, your gaming consoles are all computers. So are smartphones, smartwatches, and smart TVs. (Actually, anything with “smart” in the name is pretty much guaranteed to be a computer.) Those video doorbells that show you who’s at the door? Those are computers. Vacuuming robots, fancy touchscreen thermostats, and display consoles in cars are all computers, too. Drones are computers with propellers, and Tesla cars are computers with seats and wheels. Those cool rovers NASA sent to Mars are computers. ATMs at the bank that you can use to withdraw cash from an account? Those are computers, as are self-­checkout machines at your local grocery store. You get the idea. There are lots and lots of computers out there, and most look nothing like what we typically call a computer.

So, what makes all of these devices computers? They are all computers because inside of them is a microprocessor, a computer chip that functions as the device’s brain. The microprocessor controls everything the device does. The display, motors, inputs, sensors, speakers, and more are all controlled by one or more microprocessors.

01fig00.jpg

So now that you know what computers are, answer these questions: Are computers smart? Is your gaming console actually smart? What about your smartphone or tablet? What do you think?

Well, sorry to be the bearer of bad news, but the answer is no, not at all. ­Computers are not very smart. In fact, quite the opposite, despite the word “smart” in some of their names, computers are actually rather dumb and useless.

Why are computers not smart? Because as powerful as they are, they themselves don’t know how to do anything. They can’t display videos on a screen, they can’t respond to mouse clicks or joystick controls, they can’t connect to the Internet, they can’t understand what you type, they can’t play your favorite games or let you video conference. By themselves computers can’t do anything useful at all…So, yep, not very smart.

But computers do indeed do all sorts of wonderful things, so how do they know how to do them? They can do those things because someone taught the computers how to do them. Someone gave the computers very specific instructions teaching them how to do all things we expect our favorite devices to do. And those instructions are indeed pretty smart.

But the real smarts belong to whomever actually created the instructions. So who does that? Who gets to teach all of the computers around us how to do fun and useful things? That’s the job of computer programmers, and computer programming is just that, teaching computers how to do stuff.

How do we talk to computers?

When you talk to your friends, they understand what you are saying (well, hopefully). The reason that they understand you is that you are communicating in the same language, one you both understand. This is obviously important. If you spoke to someone who only understood another language, you’d not really be communicating.

Communicating with a computer is much the same. If you are going to give a computer instructions, you need to provide those instructions in a language that the computer understands. You are going to use a computer programming language, and much like spoken languages, programming languages have words and rules for how they are used.

There are lots and lots of different computer languages. Some have very specific uses, some are more general purpose. And most programmers learn and use multiple languages; that way they can pick the best one for any particular situation. If the idea of having to learn lots of languages sounds scary, don’t worry, we have some good news for you:

  • Exact language details, the words you use and how you use them (programmers call this syntax) differ from one language to the next. But unlike spoken languages, computer programming languages tend to have very few words and rules, so you’ll master them pretty quickly.

  • In addition, pretty much all programming languages do the same basic things (and we’ll cover all of those in this book). This means that once you master one programming language, learning the next one is much easier.

  • You never need to memorize a programming language. If you ever need a reminder for how to perform a specific task in a specific language, do what professional programmers do: Google it.

  • There is one important difference between spoken languages and programming languages, and that is the listener. When you message a friend, you can misspell words (don’t), omit punctuation (don’t do that, either), even send incomplete sentences (ugh, no, please), and your friend will still understand you. Computers are less forgiving (not smart, remember?) and if you miss a . or a }, they’ll get upset and not know what you want them to do. This is probably the single biggest source of frustration for beginning coders. So why did we point this out among this list of good news? Because editors (the tools you use to write your code…more on that soon) are really good at catching those typos, and that makes things a whole lot less frustrating.

Now that you know what a programming language is, and why they are similar to spoken languages, we are going to let you in on a secret; well, two secrets, actually. We are going to tell you exactly what computer programming is and what programmers do:

  • Imagine that you knew every word in your spoken language. You studied your dictionary backward and forward and mastered every single word, including pronunciations and definitions. Would that make you a best-­selling author? Would knowing all the words mean that you could write the next blockbuster movie script? Of course not. Knowing the words is one thing. Knowing how to use those words by creatively combining them in any of infinite combinations, well, that’s obviously very different. Computer languages are much the same. Knowing the syntax is easy (especially as computer languages have far fewer words than spoken languages). What makes an experienced and skilled programmer is knowing how to use those language elements to artfully solve problems, and that’s exactly what we’re going to help you learn. And that is a skill that takes time and practice.

  • Once more, think about spoken languages. Is there a single right way to share an idea using words? No, of course not. If that were the case, all movies and books would be the same, and that would be horrible! A language is a tool, and authors get to use that tool to craft all sorts of wonderful and unique experiences. Using a programming language is much the same. There is no single right way to write code or solve any specific problem. Rather, there are as many solutions as there are coders. We’ll show you lots of techniques and solutions in this book, and you are free to use them in your own coding. But, over time, you’ll find your own creative ways to solve problems, just like professional coders do, because coding is all about creative problem solving.

What is Python?

All of this brings us to Python, which is <make a drumroll sound here please> … a programming language.

Yes, Python is a language, and it is used to provide instructions to a computer. Python is not a new programming language, it’s actually been around for 30 years or so. But it is super popular, and even powers some of your favorite sites and apps. Why is Python so popular?

  • Python is really easy to use, no complicated tools or setups, just write a few lines of code and off you go. Really! In fact, you’ll have written code that works before you finish this chapter!

  • Python’s creators worked really hard to create a language whose syntax is really easy to read. Reading Python code is a lot like reading English. Most other programming languages are far more complicated to read. (Trust us on that one.)

  • Those syntax rules we mentioned before, the ones that frustrate most beginning coders? Python’s syntax is one of the easiest of any programming language, and we all like fewer rules, right?

  • Simple to use and having less rigid rules are great, but what really makes Python so much fun to work with is all of the libraries it makes available. We’ll discuss libraries later in the book, but for now, all you need to know is that libraries are sets of code that other programmers have written for you; just download them and use them. So, tasks that might be complicated (for example, embedding Google maps and directions in an app or detecting when a car hits an obstacle in a game) are so much simpler. You don’t have to start from scratch—you get to build on top of what other smart coders have kindly shared.

So we are going to learn Python together. But, as we explained before, what we’ll learn are the concepts and techniques that are useful in all languages. Once you’re done with this book, you will be able to apply your hard-earned knowledge and expertise to whatever language you decide to use next.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020