Study Guide - Introduction To Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

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.

 Programming languages - Programming languages are similar to human spoken


languages in that they both use syntax and semantics. Programming languages are used
to write computer programs. Some common programming languages include Python,
Java, C, C++, C#, and R.

 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.

 Semantics - Semantics refers to the intended meaning or effect of statements, or


collections of words, in both human and computer languages. Semantic errors are also
referred to as logical errors.

 Computer program - A computer program is a step-by-step list of instructions that a


computer follows to reach an intended goal. It is important to be clear and precise about
the actions a computer program is supposed to perform because computers will do
exactly what they are instructed to do. Computer programs can be long, complex, and
accomplish a variety of tasks. They are often developed by computer programmers and
software engineers, but anyone can learn to create them. Computer programs may
involve a structured development cycle. They can be written in a wide variety of
programming languages, such as Python, Java, C++, R, and more. The completed format
of a program is often a single executable file.

 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.

 Functions - A function is a reusable block of code that performs a specific task.

 Variables - Variables are used to temporarily store changeable values in programming


code.

Python Resources
More About Python

Using Python on your own

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.

Python practice resources

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

Additional Python resources

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 history and current status

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:

 The Incredible Growth of Python (Stack Overflow)


 Why is Python Growing So Quickly - Future Trends (Netguru)
 By the numbers: Python community trends in 2017/2018 (Opensource.com)
 Developer Survey Results 2018 (Stack Overflow)

A Note on Syntax and Code Blocks


When writing code, using correct syntax is critical. Even a small typo, like a missing parenthesis
bracket or an extra comma, can cause a syntax error and the code won't execute at all. If your
code results in an error or an exception, pay close attention to syntax and watch out for minor
mistakes. A single wrong character could take hours to identify in long code so it is important to
be mindful of syntax when writing code.

Common syntax errors:

 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:

 Creating functional code, but getting unintentional output


 Poor logic structures in the design of the code

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.

Study Guide: Introduction to Python


This study guide provides a quick-reference summary of what you learned in this
lesson and serves as a guide for the upcoming practice quiz.

In this segment, you learned that Python is a general-purpose programming


language that is commonly used for scripting and automation, as well as to develop
a wide variety of applications. Python is compatible with most operating systems,
including Windows, Linux, and Mac OS, and is updated every few years. Python can
also run on a variety of machines, such as servers, workstations, PCs, mobile devices,
IoT, and more.

Python is widely used in the IT field, including IT support, system administration,


web development, machine learning, data analytics, and more. Python can be used
to calculate statistics, run your e-commerce site, process images, interact with web
services, and do a whole host of other tasks. Python instructions resemble the
English language, which is what makes it easier to learn and understand when
compared to other programming languages.

Python is:

 a general purpose scripting language;


 a popular language used to code a variety of applications;
 a frequently used tool for automation;
 a cross-platform compatible language;
 a beginner-friendly language.

Python is not:

 a platform-specific / OS-specific scripting language;


 a client-side scripting language;
 a purely object-oriented programming language.

Code comparison with Python

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?

Hello, how are you? 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.

Study Guide: First Programming Concepts


This study guide provides a quick-reference summary of what you learned in this
lesson and serves as a guide for the upcoming practice quiz.

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:

 x+y Addition + operator returns the sum of x plus y


 x-y Subtraction - operator returns the difference of x minus y
 x*y Multiplication * operator returns the product of x times y
 x/y Division / operator returns the quotient of x divided by y
 x**e Exponent ** operator returns the result of raising x to the power of
e
 x**2 Square expression returns x squared
 x**3 Cube expression returns x cubed
 x**(1/2) Square root (½) or (0.5) fractional exponent operator returns the
square root of x
 x // y Floor division operator returns the integer part of the integer
division of x by y

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

 Use the print() function to output a string

8
Skill 2

 Use arithmetic operators, with a focus on exponents

Skill 3

 Use variables with assignment and arithmetic operators

Reminder: Correct syntax is critical


Using precise syntax is critical when writing code in any programming language,
including Python. Even a small typo can cause a syntax error and the automated
Python-coded quiz grader will mark your code as incorrect. This reflects real life
coding errors in the sense that a single error in spelling, case, punctuation, etc. can
cause your code to fail. Coding problems caused by imprecise syntax will always be

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.

Common syntax errors:

 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy