0% found this document useful (0 votes)
5 views

RSPP En-Us SG m05 Progintro

Uploaded by

michellekangethe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

RSPP En-Us SG m05 Progintro

Uploaded by

michellekangethe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Introduction to Programming

Python Fundamentals

Name of presenter
Date

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Welcome to Introduction to Programming.


What is programming?
What you will learn

At the core of the lesson


You will learn how to:
• Define programming
• Explain the function and features of an integrated
development environment (IDE)
• Describe the cycle of programming

In this lesson, you will learn how to:

• Define programming
• Explain the function and features of an integrated development environment (IDE)
• Describe the cycle of programming
A purpose for programming: Automation

Automation refers to any technology that removes human interaction from a system, equipment, or
process.
Scripts are often written to automate labor-intensive tasks and streamline workflows.
Before you automate a process, consider the following:

How much Identify the Find the balance Don’t


automation is proper between over- automate a
needed to achieve processes to automation and bad
your goals? automate. under-automation. process.

4
What is a programming language?

A programing language is a language that communicates instructions to a computer.


Possible instructions are:

Perform calculations. Analyze some text. Read and write files.

Display an image on Accept input from


the screen. the user.

5
How is software written?

Software is written by using text files.

Software is written by using a computer language.

6
Software is written by using text files

• Some text editors* include features that help programmers write code.
• Examples:
– Microsoft Visual Studio Code
– Sublime Text Software is written by using text files.
– Vi or Vim
– nano
– GNU emacs
– Notepad++ Software is written by using a
computer language.
– TextEdit

*Microsoft Word is not a text editor.

7
Software is written by using a computer language

• Many different languages exist


• Each language has its own:
– Grammar and syntax
– Common uses Software is written by using text files.
– Community
• Examples:
– Python
– JavaScript Software is written by using a
computer language.
– C#
– C/C++

8
Programming language elements

Like human languages,


programming languages have:

Punctuation Grammar
(operators, (structure,
delimiters) syntax)

Vocabulary
(keywords, identifiers)

9
Integrated development environment (IDE)

An IDE can tell you which Some IDEs work with only
words are spelled incorrectly, one language, such as
Most IDEs will suggest
which phrases are unclear, PyCharm for Python. It will
a fix for the issue.
and syntax that you wrote not show syntax errors for
incorrectly. Java or C# to you.

10
Compilers and interpreters

Compilers and interpreters


take the high-level language that
you are developing in, and turn
it into low-level machine code.

Compilers do this process all at


Interpreters do this process one
one time after changes are
step at a time while the code is
made, but before it runs the
running.
code.

11
Compiled and interpreted languages

• C/C++ • Python
• Basic • Ruby
• GoLang (the language that • JavaScript
Google developed)

Compiled languages Interpreted languages

12

JavaScript is interpreted when it is loaded into a webpage.


Java is compiled before the program runs on a computer.
Run, debug, and correct software

You must run your Finally, continue working on


program often. your program.

Next, find the exact


Next, fix the problem.
line that does not work.

13
Software is written iteratively

Write a
little.

Test it. Test it.

Write a Fix what


little does n't
more. work.

Test it.
14
Categorize a value as a data type
What you will learn

At the core of the lesson


You will learn how to:
• Define the term data type
• Correctly match data types to data
• Assign values to variables and variables to data types

16

In this lesson, you will learn how to:

• Define the term data type


• Correctly match data types to data
• Assign values to variables and variables to data types
What is a data type?

A data type is the classification of a value that tells the computer how the programmer intends the
data to be interpreted.
Examples:

Data Value Data Type


45 Integer
290578L Long
1.02 Float
True Boolean
“My dog is on the bed.” String
“45” String

17
Why must the type of data be tagged?

• In memory, everything consists of 0s and 1s.


• Data typing tells the computer how to:
– Encode a data value into memory
– Decode a data value out of memory

In memory In code
This is an integer.
0000 0001 1
This is a Boolean.
0000 0001 True
This is an integer.
0100 0001 65
This is a string.
0100 0001 A

18
Activity: Identify Data Instructions
1. For each value, identify the data type:
Types
1. “The Martian”
2. 1.618
3. 10082L
4. False
5. “True”

19

“The Martian” - String


1.618 - Float
10082L - Long
False - Boolean
“True” - String
What is a variable?

• A variable is an identifier in your code that represents a value in memory.


• The variable name helps humans to remember what the value means.

In memory Variable Value


0000 0001 daysOnJob 1
0000 0001 isCoder True

20
Assigning a variable to a value

• Nearly all languages have an assignment operator.


• Most languages use the equal sign (=).

Python VB.NET
isCoder = True daysOnJob = 1

F# Pascal
daysOnJob <- 1 isCoder := true

21
Assigning a data type to a variable

• Some languages expect the data type to be included when first using the variable.

Objective C
int daysOnJob = 1

Java
boolean isCoder = true

22
Assigning a data type to a variable, continued

• Some languages infer the data type based on the value that is assigned.

Python
count = 10

Swift
var daysOnJob = 1

TypeScript
let isCoder = true

23
Activity: Represent letters as numbers

American Standards Association for Information Interchange (ASCII) is a system that associates encoding
characters into computers.
Use the ASCII table at ASCII Table to decipher the following message:

72 – 97 – 118 – 101 – 32 – 121 – 111 – 117 – 32 – 115 – 101 – 101 – 110 – 32

Space
109 – 121 – 32 – 99 – 97 – 114 – 32 – 107 – 101 – 121 – 115 – 63

24
Activity: Represent letters as numbers

American Standards Association for Information Interchange (ASCII) is a system that associates encoding
characters into computers.
Use the ASCII table at ASCII Table to decipher the following message:

72 – 97 – 118 – 101 – 32 – 121 – 111 – 117 – 32 – 115 – 101 – 101 – 110 – 32

H a v e y o u s e e n

Space
109 – 121 – 32 – 99 – 97 – 114 – 32 – 107 – 101 – 121 – 115 – 63

m y c a r k e y s ?
25

Answer: Have you seen my car keys?


Combine values into composite data types
What you will learn

At the core of the lesson


You will learn how to:
• Define composite data types
• Identify composite data types from a list of properties
• List the attributes of a function
• Define different types of collections
• Combine values into a composite data type

27

In this lesson, you will learn how to:

• Define composite data types


• Identify composite data types from a list of properties
• List the attributes of a function
• Define different types of collections
• Combine values into a composite data type
What is a composite data type?

Until now, you have used primitive data types.

• Data types that are built into a


Primitive data type coding language with no
modification

• Combines multiple data types into


Composite data type a single unit

All modern programming languages have a way to create composite data types.

28
Composite data type example: Movie

Each movie could be described with:


• A name (data type would be a string)
• A year that it was released (data type would be a number, or integer)
• A flag to indicate whether you have seen it or not (data type would be a Boolean)

String

+ +
Name Year Flag

29
Composite data type 1

Name CreationTime Extension

IsReadOnly Length

30
Composite data type 2

Top Height IsEmpty

Left Location Right

Bottom Size Width

31
Composite data type 3

Age Culture Description

Gender Name Supported_AudioFormats

32
Functions
Functions
Functions do something useful.

Functions can return a value (to be stored in a variable). • The following slides provide
examples of each of these
Functions can return a value based on input values. attributes.

Functions can accept values as input.

Functions can accept many values as input.

Or, a developer can create a composite data type.

Composite data types can be returned.

Composite data types can be in an array.


34
Functions, continued
Functions do something useful. clearScreen()

Functions can return a value (to be stored in a variable).

Functions can return a value based on input values.

Functions can accept values as input.

Functions can accept many values as input.

Or, a developer can create a composite data type.

Composite data types can be returned.

Composite data types can be in an array.


35
Functions, continued
Functions do something useful.

Functions can return a value (to be stored in a variable). pi = calculatePi()

Functions can return a value based on input values.

Functions can accept values as input.

Functions can accept many values as input.

Or, a developer can create a composite data type.

Composite data types can be returned.

Composite data types can be in an array.


36
Functions, continued
Functions do something useful.

Functions can return a value (to be stored in a variable).

Functions can return a value based on input values. area = calculateArea(pi, 4)

Functions can accept values as input.

Functions can accept many values as input.

Or, a developer can create a composite data type.

Composite data types can be returned.

Composite data types can be in an array.


37
Functions, continued
Functions do something useful.

Functions can return a value (to be stored in a variable).

Functions can return a value based on input values.

Functions can accept values as input. showValue(area)

Functions can accept many values as input.

Or, a developer can create a composite data type.

Composite data types can be returned.

Composite data types can be in an array.


38
Functions, continued
Functions do something useful.

Functions can return a value (to be stored in a variable).

Functions can return a value based on input values.

Functions can accept values as input.

fly(lat, lon, spd, hdg,


Functions can accept many values as input.
vspd, wspd, wdir)

Or, a developer can create a composite data type.

Composite data types can be returned.

Composite data types can be in an array.


39
Functions, continued
Functions do something useful.

Functions can return a value (to be stored in a variable).

Functions can return a value based on input values.


fly(aircraft)
Functions can accept values as input.
latitude
Functions can accept many values as input.
longitude
speed
Or, a developer can create a composite data type.
heading
verticalSpeed
Composite data types can be returned.
windSpeed
Composite data types can be in an array. windDirection
40
Functions, continued
Functions do something useful.

Functions can return a value (to be stored in a variable).

Functions can return a value based on input values.


aircraftFuture =
predict(aircraftNow, 60)
Functions can accept values as input.

latitude
Functions can accept many values as input.
longitude
speed
Or, a developer can create a composite data type.
heading
Composite data types can be returned. verticalSpeed
windSpeed
Composite data types can be in an array. windDirection
41
Functions, continued
Functions do something useful.

Functions can return a value (to be stored in a variable).

Functions can return a value based on input values.


collisions =
predict(allAircraft)
Functions can accept values as input.

latitude
Functions can accept many values as input.
longitude
Or, a developer can create a composite data type. speed
heading
Composite data types can be returned. verticalSpeed
windSpeed
Composite data types can be in an array. windDirection
42
Collections

A collection groups multiple values in a single variable. Different types of collections are available:

Arrays Vector Lists Set

Deque
Queue (double-ended Hashes Dictionaries
queue)

The next few slides provides examples of collections.

43
Example collection: Array

The table shows a basic array of ages. Each age is Slot Data Type Value
assigned a slot, is of the same data type, and is adjacent
to the previous age and the next age in memory. 0 Integer 87
1 Integer 10
• The first slot is almost always 0 in every language. 2 Integer 2
• Notice that the values do not need to be in any order.
3 Integer 46
4 Integer 22
5 Integer 19
6 Integer 66

44
Python collection example: List

A Python List is an ordered collection of items. Index Data Type Value


• Each item can be of a different data type. 0 String “John”
• Items can be accessed using an index.
1 Integer 55
• Items can have duplicate values.
2 Boolean True
3 String “male”
4 String “Carlos”
5 Integer 22
6 String “male”

45

A Python list is ordered because each new item is added to the end of the list.
Follow the execution path of a program
What you will learn

At the core of the lesson


You will learn how to:
• Explain what an execution path is
• Describe the use of different types of flow control mechanisms, including loops,
conditionals, and switches

47

In this lesson, you will learn how to:

• Explain what an execution path is


• Describe the use of different types of flow control mechanisms, including loops,
conditionals, and switches
What does execution path mean?

• The sequence of steps that the program performs when it runs


• The program might …
– Come to an either-or choice
– Come to multiple choices
– Perform work on each item in a loop
• The programmer must be able to predict what those steps will be…
– When they write the code initially
– When they debug problems that they encounter

48
Conditionals

• All programming languages have a way to choose an either-or path in the code.

if (guess > number):


print("Too high!")
elif (guess < number):
print("Too low!")
else
print(“Exactly right!")

49
Example from Python

if(name == ‘Juan'):

bonus = 300

else:

bonus = salary * 0.1

50
Switches

• Most programming languages have a way to conveniently handle multiple possible cases of a value.

switch(sign):
case "Stop": pressBreak()
case "Merge": accelerate()
case "Exit": decelerate()
default: ignore()

51
Loops

• All programming languages have a way to do something on each item in a collection.

names = {“wei", “nikki", “akua"}

for name in names:


newName = capitalize(name)
print newName

52
Example from Python

for(employee in employees):
employee.bonus = employee.salary * 0.1;

53
Version control
What you will learn

At the core of the lesson


You will learn how to:
• Explain the need for version control
• Explain the basics of Git
• Explain the difference between Git and GitHub

55

In this lesson, you will learn how to:

• Explain the need for version control


• Explain the basics of Git
• Explain the difference between Git and GitHub
Version control and collaboration

A version control system is software that tracks versions of your code and documents
as you update them.

Version control can be done locally on your computer or by using a website that is
dedicated to saving these versions.

Collaboration is doing version control, but in the cloud or on a dedicated website so


that multiple people can work on a project.

56
Advantages of version control

Error tracking

Ease of access to
Security
project changes

Version control

57
Utilizing cloud infrastructure

The cloud, or a dedicated website, is useful for storing changes in code.


Version control that is only on a local computer can be easily lost, even if it is more secure than saving
multiple versions of a file.
Data that is stored in the cloud has a reduced risk of being lost.

58
Version control tools

Several version control tools are available:


• Git and GitHub
• GNU arch
• Mercurial
More version control tools exist, but the one that this course focuses on is Git and GitHub.

Mercurial GitHub

Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

59
Git
Install the Git tools

Add files to a repository

Edit files in a Git repository

Clone an existing repository

Create and merge branches

Rewrite history in a Git repository

Resolve merge conflicts


60
Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.
Git, continued

The best way to learn Git is to experience it.


1. Install the Git Tools from the website: About Git.
2. After you install the Git Tools, open the Git Bash program.
3. In the Bash terminal, create a folder or directory that is named GitTest by entering: mkdir GitTest
4. Change directories by entering: cd GitTest
5. Create a local Git repository by entering: git init
6. Confirm that a new repository is there, by entering ls -ldF .* and looking for the .git repository.
7. Next, create a new file by entering: touch newFile.txt
8. Open the new file by entering: nano newFile.txt

61
Git, continued

9. Enter any text that you want.


10. To exit from nano, press CTRL+X.
11. In the terminal, enter: git status
You should see newFile.txt in red characters.
12. Now, add newFile.txt to the local Git repository by entering git add newFile.txt and then git
status
You should see that newFile.txt is in now in green characters, which means that it is ready to be
committed.
13. To finish the process, enter git commit -m “Initial commit” followed by git status to confirm that
Git is not tracking any new changes.

62
Git, continued

If the commit message did not work, you most likely saw a message that said Please tell me who you
are in the terminal.
14. To clear this message, in the terminal, enter the following two commands :
– git config –global user.email “<[email protected]>”
» Replace <[email protected]> with an email address that you actually own and want to
use for this course.
» The rest of the command is entered exactly, including the quotation marks (“ “).
– git config –global user.name “<Your name>”
» Replace <Your name> with a user name that you want to use for this course. Make it
unique.
» The rest of the command is entered exactly, including the quotation marks.

63
Git, continued

15. After you are finished, enter git commit -m “Initial commit” again, followed by git status to
confirm that Git is not tracking any new changes.

64
GitHub
GitHub is a repository hosting service. It uses repositories and the same commands as the terminal.
To prepare for the lab, create a GitHub account on GitHub, if you don’t already have one.
Sites like GitHub are also a good way to exhibit your code to developers and potential employers.

65
Checkpoint questions

What is one of the key purposes of programming?

Which types of files are used to store programming source code?

What is an IDE?

What data type is a whole number?

What is the purpose of functions in programming?

Name one popular version control tool.

66

Answers:
1. From the lesson, it was shown that automation is one of the uses of
programming.
2. Programs are written in text files.
3. An IDE is an integrated development environment that helps with writing code.
4. Whole numbers are typically stored as integers.
5. Functions enable developers to create discrete sections of code that can be called
by using the function’s name. The resulting function is then available to the rest of
the source code.
6. Git.
• Programming is a way to automate processes.
Key takeaways
• Programming languages specify a way to
communicate directions to a computer.
• Software is written into a text file by using a
programming language, which is either interpreted
or compiled when it is run.
• Data is typed so that the interpreter or compiler
knows whether it is a string, integer, Boolean, or
other data type.
• A composite data type stores different types of data
in a single variable.
• Functions are collections of instructions that can be
called repeatedly in a program.
• Version control manages changes to computer
programs, documents, or other collections of
information.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

67

Some key takeaways from this lesson include:

• Programming is a way to automate processes.

• Programming languages specify a way to communicate directions to a computer.

• Software is written into a text file by using a programming language, which is


either interpreted or compiled when it is run.

• Data is typed so that the interpreter or compiler knows whether it is a string,


integer, Boolean, or other data type.

• A composite data type stores different types of data in a single variable.

• Functions are collections of instructions that can be called repeatedly in a


program.

• Version control manages changes to computer programs, documents, or other


collections of information.

You might also like