Study Guide - Introduction To Programming
Study Guide - Introduction To Programming
Study Guide - Introduction To Programming
Your first practice quiz is coming up soon. This handy study guide should help you prepare for
that quiz. The practice quizzes do not count towards your grade in this course. Practice quizzes
are opportunities for you to check your understanding of the materials before you take the
graded assessments at the end of each module.
Key Terms
Programming code - Programming code is a set of written computer instructions, guided
by rules, using a computer programming language. It might help to think of the
computer instructions as a detailed, step-by-step recipe for performing tasks. The
instructions tell computers and machines how to perform an action. Programming code
may also be referred to as source code or scripts.
Syntax - Syntax is a set of rules for how statements are constructed in both human and
computer languages. Programming syntax includes rules for the order of elements in
programming instructions, as well as the use of special characters and their placements
in statements. This concept is similar to the syntax rules for grammar and punctuation in
human language.
Script - Scripts are usually shorter and less complex than computer programs. Scripts
are often used to automate specific tasks. However, they can be used for complex tasks if
needed. Scripts are often written by IT professionals, but anyone can learn to write
scripts. Scripts have a shorter, less structured development cycle as compared to the
development of complex computer programs and software. Scripts can be written in a
variety of programming languages, like Python, Javascript, Ruby, Bash, and more. Some
scripting languages are interpreted languages and are only compatible with certain
platforms.
Automation - Automation is used to replace a repetitive manual step with one that
happens automatically.
1
Output - Output is the end result of a task performed by a function or computer
program. Output can include a single value, a report, entries into a database, and more.
Input - Input is information that is provided to a program by the end user. Input can be
text, voice, images, biometrics, and more.
Python Resources
More About Python
The best way to learn any programming language is to practice it on your own as
much as you can. If you have Python installed on your computer, you can execute the
interpreter by running the python3 command (or just python on Windows), and you
can close it by typing exit() or Ctrl-D.
If you don’t already have Python installed on your machine, that’s alright. We’ll
explain how to install it in an upcoming course.
In the meantime, you can still practice by using one of the many online Python
interpreters or codepads available online. There’s not much difference between an
interpreter and a codepad. An interpreter is more interactive than a codepad, but
they both let you execute code and see the results.
Below, you’ll find links to some of the most popular online interpreters and
codepads. Give them a go to find your favorite.
https://www.python.org/shell/
https://www.onlinegdb.com/online_python_interpreter
https://repl.it/languages/python3
https://www.tutorialspoint.com/execute_python3_online.php
https://rextester.com/l/python3_online_compiler
https://trinket.io/python3
While this course will give you information about how Python works and how to
write scripts in Python, you’ll likely want to find out more about specific parts of the
language. Here are some great ways to help you find additional info:
2
Read the official Python documentation.
Search for answers or ask a question on Stack Overflow.
Subscribe to the Python tutor mailing list, where you can ask questions and
collaborate with other Python learners.
Subscribe to the Python-announce mailing list to read about the latest
updates in the language.
Python was released almost 30 years ago and has a rich history. You can read more
about it on the History of Python Wikipedia page or in the section on the history of
the software from the official Python documentation.
Python has recently been called the fastest growing programming language. If you're
interested in why this is and how it’s measured, you can find out more in these
articles:
Misspellings
Incorrect indentations
Missing or incorrect key characters:
o Bracket types - ( curved ), [ square ], { curly }
o Quote types - "straight-double" or 'straight-single', “curly-double” or ‘curly-
single’
o Block introduction characters, like colons - :
Data type mismatches
Missing, incorrectly used, or misplaced Python reserved words
Using the wrong case (uppercase/lowercase) - Python is a case-sensitive language
If your syntax is correct, but the script has unexpected behavior or output, this may be due to a
semantic problem. Syntax is like the vocabulary, grammar, spelling, and punctuation of code.
Semantics are the meaning and logic of coded statements. It is possible to have syntactically
correct code that runs successfully, but doesn't do what we want it to do.
3
Common semantic errors:
When working with the code blocks in exercises for this course, be mindful of syntax and
semantic (logic) errors, along with the overall result of your code. Just because you fixed an error
doesn't mean that the code will have the desired effect when it runs! Once you’ve fixed an error
in your code, don't forget to click Run to check your work.
Python is:
Python is not:
You will be learning about both Python and Bash scripting in this program. The
following code illustrates a syntax difference between the two languages:
4
Print to screen in Python Print to screen in Bash
>> print("Hello, how are you?") >> echo Hello, how are you?
Key Terms
Platform-specific / OS specific scripting language - Platform-specific
scripting languages, like PowerShell (for Windows) and Bash (for Linux), are
used by system administrators on those platforms.
Client-side scripting language - Client-side scripting languages, like
JavaScript, are used mostly for web programming. The scripts are transferred
from a web server to the end-user’s internet browser, then executed in the
browser.
Machine language - Machine language is the lowest-level computer language.
It communicates directly with computing machines in binary code (ones and
zeros). In binary code, one equals a pulse of electricity and zero equals no
electrical pulse. Machine language instructions are made from translating
languages like Python into complex patterns of ones and zeros.
Cross-platform language - Programming language that is compatible with
one or more platforms / operating systems (e.g., Windows, Linux, Mac, iOS,
Android).
Object-oriented programming language - In object-oriented programming
languages, most coding elements are considered to be objects with
configurable properties. For example, a form field is an object that can be
configured to accept only dates as input in the mm/dd/yy format, and can be
configured to read from and write to a specific database.
Python interpreter - An interpreter is the program that reads and executes
Python code by translating Python code into computer instructions.
Resources
For additional Python practice, the following links will take you to several popular
online interpreters and codepads:
Welcome to Python
Online Python Interpreter
Create a new Repl
Online Python-3 Compiler (Interpreter)
Compile Python 3 Online
Your Python Trinket
5
Functions are pieces of code that perform a unit of work. We'll talk a lot more about functions
later on, and you'll even learn how to write your own. Keywords are reserved words that are
used to construct instructions. These words are the core part of the language and can only be
used in specific ways. Some examples include if, while, and for. We'll explain all of those and a
bunch more later in the course. As we called out, the keywords and functions used in Python
are what makes up the syntax of the language. Once we understand how they work, we can
use them to construct more complex expressions that get the computer to do what we want
it to do. Last off, notice how hello world is written between double quotation marks.
Wrapping text in quotation marks indicates that the text is considered a string, which means
it's text that will be manipulated by our script. In programming, any text that isn't inside
quotation marks is considered part of the code. Now, for a bit of trivia, do you know why we
printed the whole world in our example? Well, printing hello world has been the traditional
way to start learning a programming language since way back in the '70s when it was used as
the first example in a famous programming book called the C programming language. That
example looked like this.
In Python, the hello world example is just one line, in C, it's three lines, in other languages, it
can be even more. While learning to write hello world won't teach you the whole language, it
gives you a first impression of how functions are used, and how a program written in that
language looks.
Functions
A function is a piece of code that performs a unit of work. In the examples you've
seen so far, you have only encountered the print() function, which outputs a
message to the screen. You will use this function frequently in this course to check
the results of your code. The syntax of the print() function is modeled in the example
below.
# Syntax for printing a string of text. Click Run to check the result.
print("Hello world!")
6
RunReset
Hello world!
Keywords
A keyword is a reserved word in a programming language that performs a specific
purpose. In your first Python example, you briefly encountered the keywords for and
in. Note that keywords will often appear in bold in this course.
In the next few weeks, you will also learn the following keywords:
Values: True, False, None Conditions: if, elif, else Logical operators: and, or, not
Loops: for, in, while, break, continue Functions: def, return
You don't need to learn this whole list now. We'll dive into each keyword as we
encounter them. There are additional reserved keywords in Python. If you would like
to read about them, please visit the linked “Python Keywords” article in the
Resources section at the end of this study guide.
Arithmetic operators
Python can calculate numbers using common mathematical operators, along with
some special operators, too:
7
x%y Modulo operator returns the remainder part of the integer division
of x by y
Order of operations
The order of operations are to be calculated from left to right in the following order:
1. Parentheses ( ), { }, [ ]
2. Exponents xe (x**e)
3. Multiplication * and Division /
4. Addition + and Subtraction -
You might find the PEMDAS mnemonic device to be helpful in remembering the
order.
for i in range(5):
print("This is fun!")
Coding skills
Skill 1
8
Skill 2
Skill 3
9
an issue whether you are learning a programming language or you are using
programming skills on the job. So, it is critical to start the habit of being precise in
your code now.
No credit will be given if there are any coding errors on the automated graded
quizzes - including minor errors. Fortunately, you have 3 optional retake
opportunities on the graded quizzes in this course. Additionally, you have unlimited
retakes on practice quizzes and can review the videos and readings as many times as
you need to master the concepts in this course.
Now, before starting the graded quiz, review this list of common syntax errors coders
make when writing code.
Misspellings
Incorrect indentations
Missing or incorrect key characters:
o Parenthetical types - ( curved ), [ square ], { curly }
o Quote types - "straight-double" or 'straight-single', “curly-double” or
‘curly-single’
o Block introduction characters, like colons - :
Data type mismatches
Missing, incorrectly used, or misplaced Python reserved words
Using the wrong case (uppercase/lowercase) - Python is a case-sensitive
language
10