SIC - C&P - Chapter 1. Unit 1
SIC - C&P - Chapter 1. Unit 1
Innovation
Campus
Coding and Programming
Chapter 1.
Chapter objectives
Learners will be able to configure a practice environment for Python and learn the basics of
programming. Learners will become familiar with the foundations of Python such as input/output,
data types, and variables. Furthermore, they will acquire problem solving skills in coding through
various operators, conditionals, and loops.
Chapter contents
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 3
Orientation
Introduction to Python
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 4
Introduction to Python Orientation
What is Python?
Python is a high-level programming language and is one of the most popular programming languages in
the world.
Python is a general purpose language that is broadly applicable across application domains. Therefore,
Python is widely used to create a variety of different programs. It is used in everything from data sci-
ence, web development, automation to generally getting stuff done.
Because of its versatility, Python can be used by developers and non-developers alike.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 5
Introduction to Python Orientation
Python syntax
Interpreted
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 6
Introduction to Python Orientation
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 7
Introduction to Python Orientation
Major companies that use Python ‣ TensorFlow is based on dataflow and differential
programming, which focuses on deep neural
networks for machine learning.
‣ Keras provides an interface for artificial neural
networks with a focus on enabling fast
experimentation.
https://light-it.net/blog/top-10-python-libraries-for-ma-
chine-learning/
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 8
Introduction to Python Orientation
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 9
Introduction to Python Orientation
Artificial Intelli-
Data Science
gence Game Develop-
& Web Development
& ment
Data Visualization
Machine Learning
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 10
Introduction to Python Orientation
By completing this course, you will be prepared to join the entry level job position that requires basic
Python skill.
Basic Python
Algorithm for
Data Analysis
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 11
Introduction to Python Orientation
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 12
Unit 1.
Sequential Programming
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 13
Unit learning objective (1/3) UNIT
01
Learning objectives
Learners will be able to explain the definition and necessity of computational thinking.
Learners will be able to install necessary software for Python from scratch.
Learners will be able to configure a new virtual environment where Python 3.x is installed, and
will be able to install different versions of Python.
Learners will be able to infer the coding sequence by looking at the output result using only the
print function.
Learners will be able to distinguish between syntax errors and runtime errors.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 14
Unit learning objective (2/3) UNIT
01
Learning overview
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 15
Unit learning objective (3/3) UNIT
01
Keywords
Computa-
Virtual Envi- Jupyter
tional think-
ronment Notebook
ing
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 16
Unit Sequential Programming
01.
Mission
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python
Mission UNIT
01
https://www.oecd.org/education/2030-project/teaching-and-
learning/learning
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 18
Mission UNIT
01
Computational Think-
ing
https://www.battelleforkids.org/networks/p21/frame-
works-resources
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 19
Mission UNIT
01
2. Solution
2.1. Thinking like a Computer
※ To view the video clip above, move your mouse onto video screen to appear the
play button.
https://youtu.be/
1mLQFm3wEfw
2. Solution
2.2. The 3 Structures of Program-
ming
To think and solve problems like a computer scientist, you need to understand the fundamentals of how
programming works.
While learning Python throughout this course, you will learn to improve efficiency by minimizing repetitive
tasks, operating in sequence and making decisions based on clear conditions.
The first task is to use the print() function to learn sequential structure and make a program operating in
order.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 22
Mission UNIT
01
3. Mission
3.1. Create a Program that Prints Your Re-
sume
This video shows the final result of what you will produce from this unit. Take a look at this program and
figure out pieces of knowledge you can use and you should learn, and think about how to make a plan to
create it.
※ To view the video clip above, move your mouse onto video screen to appear the play but-
ton.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 23
Mission UNIT
01
3. Mission
3.2. Program Planning
Pseudocode Flowchart
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 24
Mission UNIT
01
3. Mission
3.3. Resume Program: Final Codes
Here is the final code of the program you will create in this unit. But this code is not presented for you to
copy.
It is to encourage you to imagine the necessary process by knowing the final the result.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 25
Unit Sequential Programming
01.
Key concept
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python
Key concept UNIT
01
1. Sequence
1.1. Definition and Importance of
Sequence
Sequence is the order in which a computer executes its codes.
Since the program is very fast, it may look like codes are being executed simultaneously, but in reality the
computer processes commands in sequence.
Naturally, even with the same commands, if the order changes, then a completely different result is
produced.
When writing a code in Python, the priority and purpose of the commands should be considered before
deciding their order.
Sequence is important in everyday How could the changed order affect the
life result?
put toothpaste on tooth-
rinse toothbrush
brush
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 27
Key concept UNIT
01
2. Basic Terminology
2.1. Using the Glossary
A glossary is provided as a learning aid. If a new term appears, it is important to note them and check the
definition.
A tutorial on Python’s official website is also recommended.
https://doc-
s.python.org/3/
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 28
Key concept UNIT
01
2. Basic Terminology
2.2. Expression, Statement, and
Program
Expression is a simple code that produces values such as numbers, formulas, and strings. A statement is
composed of more than one expressions and a program is composed of more than one statement.
352
10 + 20 import time
timesleep(5)
‘Hello World!’ timesleep(5)
assembleprint(‘Hello World!’)assemble
import print(‘Hello World!’)
17.2
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 29
Key concept UNIT
01
2. Basic Terminology
2.3. Annotation
Annotation is a sentence used to describe the function of the code in the program. The interpreter skips
execution of the annotation.
Annotation is very important in programming. When others modify your codes, annotations help other
programmers understand your code. For complex codes, comments are also helpful for future references.
There are two main ways to add annotations in Python. First, let's look at how to make a single line
annotation.
Adding the # sign at the beginning of the sentence will turn the line into an annotation. You haven’t
learned the code below yet, but reading the comments will help you understand them.
#define the variable as a radius
Radius 4.0
Area 50.24
Circumference 25.12
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 30
Key concept UNIT
01
2. Basic Terminology
2.3. Annotation
To create multiple-line annotations, add three small or large quotation marks at the front and back lines.
For ‘’‘ ~~ ‘’‘ or “”” ~~ “”” lines, ~~ portions are not executed.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 31
Key concept UNIT
01
2. Basic Terminology
2.4. Reserved Word
A word reserved to perform a predetermined role is called a keyword or a reserved word.
Since keywords can only execute the predetermined role in Python, they cannot be used as identifiers
such as variable name and class name. If used as an identifier, the role will overlap with the command
and cannot execute.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 32
Unit Sequential Programming
01.
Paper coding
Try to fully understand the basic concept before moving on to the next step.
Lack of understanding basic concepts will increase your burden in learning this
course, which may make you fail the course.
It may be difficult now, but for successful completion of this course we suggest
you to fully understand the concept and move on to the next step.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python
Paper coding UNIT
01
Q1
Python codes are executed in sequence. Image the 3x3 box below. Starting with the first box,
each box is colored according to the command below. One of many possible algorithms is
shown below.
. Move Right,
Start Fill-In Square,
Here
Move Right,
Move Down
Fill-In Square,
Move Left,
Move Left,
Fill-In Square
https://code.org/curriculum/ Move Down,
course2/1/Teacher
Move Right,
Fill-In Square,
Move Right
Write the entire code and the expected output results in the
note.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 34
Paper coding UNIT
01
Q2
Starting with the first box at the top left, move one space at a time, and fill in the boxes as
below.
Think about the more efficient way to execute.
.
https://code.org/curriculum/course2/1/
Teacher
Write the entire code and the expected output results in the
note.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 35
Unit Sequential Programming
01.
Let’s code
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python
Let’s code UNIT
01
1. Setting Up
1.1. Installing Anaconda
We will set up the workspace using the Anaconda. If this step is deemed unnecessary, the instructor can
decide to skip to the next section. (But starting with the virtual environment configuration part, the lesson
must be taught in order.)
First, go to the Anaconda website (www.anaconda.com) and download the Anaconda Individual Edition.
Choose an installer compatible with your computer’s operating system. (This lecture provides an example
in the Windows system.)
https://www.anaconda.com/products/in-
dividual
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 37
Let’s code UNIT
01
1. Setting Up
1.1. Installing Anaconda
After downloading and executing the anaconda installation file, follow the procedure below to install the
program.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 38
Let’s code UNIT
01
1. Setting Up
1.1. Installing Anaconda
When installing Anaconda, the computer's username must be in English. Otherwise, the program will not
install.
If a separate Python program has been previously installed, it will overlap with Python.exe of Anaconda.
Go to Advanced Options and uncheck Add Anaconda3 to my PATH environment variable. In this case, you
can execute the program by clicking on the Anaconda Prompt in the start menu.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 39
Let’s code UNIT
01
1. Setting Up
1.2. Installing Jupyter Notebook
After installing Anaconda, let’s install Jupyter Notebook. First, search and run Anaconda Navigator in the
Windows Start menu.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 40
Let’s code UNIT
01
1. Setting Up
1.2. Installing Jupyter Notebook
In the Anaconda Navigator as shown below, click the Notebook’s Install button complete the installation.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 41
Let’s code UNIT
01
python : 3.8
python : 3.7
Install pandas
data_science python_work
Computer
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 42
Let’s code UNIT
01
When the prompt "Proceeded ([y]/n)?" appears as shown in the screen below, enter y to proceed.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 43
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 44
Let’s code UNIT
01
Execution Command
Remove virtual environment conda remove --name [name of a virtual environment] --all
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 45
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 46
Let’s code UNIT
01
Try moving python_work to a different workspace by using “conda activate python the work”,
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 47
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 48
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 49
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 50
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 51
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 52
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 53
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 54
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 55
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 56
Let’s code UNIT
01
4. print( ) Function
4.1. The Basics
Both single quote and
double quote marks
print( ) code is a command that outputs values work, but the start and
inside the ( ) end symbol has to
print(“Hello match.
World!”)
The value between the open quotation and close quotation marks are
called a string.
TIP
Unlike other languages, Python automatically breaks a line after outputting a string through
print().
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 57
Let’s code UNIT
01
4. print( ) Function
4.2. Printing String and Value
To print a string using the print( ) function, you must enclose both sides of the string with quotation
marks.
To print a numerical value, enter the numbers without quotation marks. If you print a number with the
quotation mark, the data type will be an integer.
You can also perform an arithmetic operations in the print( ) function. The arithmetic operations of
number data types will be covered in Unit 3.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 58
Let’s code UNIT
01
4. print( ) Function
4.3. Adding a New Line
Python automatically breaks the line after printing a string through a print( ) function. If so, could lines
break between sentences within the same print( ) function?
Using an \n escape sequence within a string adds a new line. The escape sequence refers to a special
character used for controlling a string output.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 59
Let’s code UNIT
01
4. print( ) Function
4.3. Adding a New Line
In the print( ) function, the beginning and end of a string may be grouped with three double quotes (“””)
or three single quotes (‘’’). This will display the grouped string, including the line break, on the screen.
However, if you put a backslash( \ ) at the end of a grouped string with three quotes, the line will not be
broken, and the next line will be connected to the same line.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 60
Let’s code UNIT
01
4. print( ) Function
4.4. The Comma(,) Additions(+), Multiplication(*) Opera-
tors
A comma, addition, or multiplication operators can be used to print more diverse and efficient strings or
values.
When a comma (,) operator is used between the first and second value, it adds a space in between the
values then a line break. You may print two or more integers or values by combining it with a comma
operator.
You may also combine a string and a number with a comma operator.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 61
Let’s code UNIT
01
4. print( ) Function
4.4. The Comma(,) Additions(+), Multiplication(*) Operators
When strings are combined with an addition (+) operator, the second integer is printed after the first
integer without a space then a line break occurs. When an addition (+) operator is used with values, it will
print the result of the addition then a line break.
When using an addition (+) operator, you cannot combine strings and numbers. When a
string and a number are combined with an addition operator (+), TypeError occurs.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 62
Let’s code UNIT
01
4. print( ) Function
4.4. The Comma(,) Additions(+), Multiplication(*) Operators
When a string and a positive integer are combined using a multiplication (*) operator, the string is
repeated as many times as the number and without any space, then a line break occurs. When a
multiplication (*) operator is used for a number, a line break occurs after printing the result of the
multiplication operation.
When a string and a string are combined with a multiplication operator (*), TypeError
occurs.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 63
Let’s code UNIT
01
4. print( ) Function
4.5. End and Split Parameters
When a program encounters a print() function, a line break occurs. However, when a string is specified at
the end of the print( ) statement, the string is printed instead of the line break.
The first code prints ‘Hello’ then immediately prints ‘World!’ without breaking the line. The second code
prints a comma instead of a line break.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 64
Let’s code UNIT
01
4. print( ) Function
4.5. End and Split Parameters
The previously learned comma(,) operator within the print() function prints a space between two strings
or values. When a string is specified in the last sep of the print( ) function, the specified string is printed
instead of the space.
The first code prints ‘Hello’ then immediately prints ‘World!’ without any spaces. The second code prints a
comma instead of a space.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 65
Let’s code UNIT
01
4. print( ) Function
4.6. Creating a Resume
Below is an example code of today's mission. Let’s practice coding a resume using operators we learned
in this lesson; comma (+), multiplication (*) operator, and end and split parameter.
Also try using asterisk (*) or minus (-) symbols to decorate the resume.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 66
Let’s code UNIT
01
5. Pythonic way
5.1. Why is Pythonic Coding Important?
It is important to form a good coding style and habit from the beginning.
The main purpose of Pythonic Coding is to write clear and concise codes using characteristics that are
different from other programming languages.
Utilizing Python coding conventions used by developer communities also help in collaborating with other
developers.
There are several conventions for the Pythonic way, but we will focus on the essentials for the beginners.
‣ There are two main Python style guides.
‣ PEP8 of Python's official community and
Google’s Python Style Guide.
‣ This unit utilizes the PEP8 guide.
https://www.python.org/dev/peps/pep-
0008/
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 67
Let’s code UNIT
01
5. Pythonic way
5.2. Code lay out
Python allows writing multiple sentences in one line using semicolons as shown below. This style of
coding, however, does not have a good readability.
When coding with Python, it is recommended to use one sentence in each line as shown below.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 68
Let’s code UNIT
01
5. Pythonic way
5.2. Code lay out
A long code like below is very difficult to read.
When coding with Python, if a sentence gets too long, try making a line break. Use a backslash( \ ) to add
a line.
Finally, operators and operands have spacing in between them. When listing elements, put a space after a
comma.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 69
Let’s code UNIT
01
5. Pythonic way
5.3. Naming convention
The names used in programming, like variables, functions, classes and etc., are called identifiers. The
types of naming styles of identifiers are shown in the table below.
In Python, the names of variables and functions generally follow the Snake style, and the class names
follow the Pascal style.
Pascal Almost the same as the Camel style, but the first alphabet is also capitalized. HelloWorld
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 70
Let’s code UNIT
01
5. Pythonic way
5.3. Naming convention
Python’s conventions for naming identifiers are as follows:
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 71
Let’s code UNIT
01
5. Pythonic way
5.3. Naming convention
Examples of the correct identifiers:
Underscores can be used anywhere in the identifier, like the rest of the
my_list
characters.
__code__ The name of a specific method can start with __(two underscores).
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 72
Let’s code UNIT
01
5. Pythonic way
5.3. Naming convention
Examples of the incorrect identifiers:
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 73
Let’s code UNIT
01
6. Error
6.1. Syntax Error
Programming languages are used under strict rules and conventions. Writing a code that strays from the
grammatical rules results in a syntax error.
To prevent syntax errors, you must learn and practice Python grammar and code according to the set
rules.
To print the string ‘Hello’, quotation marks must be used on both sides of the string. However, in the code
below, a syntax error occurred because the string was not quoted.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 74
Let’s code UNIT
01
6. Error
6.2. Runtime Error
Unlike the syntax errors, grammatically correct codes can still result in error during the execution. This
type of error is called runtime error.
To prevent runtime errors, the developer should consider the possibility of user entering an incorrect data
and suggest a user-friendly request to encourage entering a correct data. Also, various exception cases
usually occur, so testing the code in various conditions is highly recommended.
In the code below, the user entered a string two instead of an integer 2, and a runtime error occurred.
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 75
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 76
Let’s code UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 77
Unit Sequential Programming
01.
Pair programing
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python
Pair programming UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 79
Pair programming UNIT 01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 80
Pair programming UNIT
01
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 81