0% found this document useful (0 votes)
1K views81 pages

SIC - C&P - Chapter 1. Unit 1

Chapter 1 Samsung course
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views81 pages

SIC - C&P - Chapter 1. Unit 1

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

Samsung

Innovation
Campus
Coding and Programming
Chapter 1.

Programing Basic Concept


and Starting Python
Coding and Programming

Samsung Innovation Campus 2


Chapter Description

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

 Unit 1. Sequential Programming


 Unit 2. Planning for Programming
 Unit 3. Basic of Numeric Data Types and Arithmetic Operation
 Unit 4. Variables and Inputs
 Unit 5. Logic and Comparison Operations
 Unit 6. Conditional Statement-1: Conditions and Decision Making
 Unit 7. Conditional Statement -2: Making decisions in two directions and applying conditional
statements
 Unit 8. Loop-1
 Unit 9. Loop-2

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.

<Most loved languages in


Python 2020> 66.70%
Pytho
n
C# 59.70%
JavaScript 58.30%
R 44.50%
Java 44.10%
C++ 43.40%
Ruby 42.90%
C 33.10%
https://insights.stackoverflow.com/sur-
vey/2020

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 5
Introduction to Python Orientation

Why is Python so popular?


Python is popular in educational fields because it is easy to read, write, and learn.
‣ Python code can be written and interpreted similarly as human’s everyday language, so it is
readable and easy to learn by beginners. Students can design the flow of the program in human lan-
guage and change it to the actual Python code very easily.
‣ Especially the syntax of Python is very simple and intuitive to write and understand, which helps new
programmers not to waste time with confusing syntax.

Python syntax

Interpreted

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 6
Introduction to Python Orientation

Why is Python so popular?


Python is also loved by major companies and applications because of its versatility.
‣ Python is wanted not only in educational fields but also by many developers in professional
workplaces. Big companies, including Google, Intel, eBay, Netflix, Instagram, Dropbox, and Slack,
utilize Python for developing and maintaining their applications.

‣ Google uses Python software development to


<Major companies that use Python> enhance its search engine capabilities.
‣ Netflix uses Python to recommend movies,
TV shows, and documentaries based on a
user’s history.
Major companies that use Python ‣ Instagram uses Python to personalize the
explore section for users.
‣ Spotify uses Python for personalized music
recommendation to its users.
‣ Reddit uses Python for web development to
https://www.botreetechnologies.com/blog/pros-and- simplify the Q&A sections.
cons-of-python/

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 7
Introduction to Python Orientation

Why is Python so popular?


Many industries use Python as it offers open-source libraries that contain built-in modules.
‣ Python includes various libraries, such as pandas, NumPy, SciPy, Matplotlib, TensorFlow, and Keras,
that can be extensively used in different fields like web development, data analytics, and artificial
intelligence.
‣ pandas is used for data manipulation and
<Python libraries> analysis, particularly featuring numerical tables
and time series operation.
‣ NumPy supports for large, multi-dimensional
arrays and matrices, along with a collection of
high-level mathematical functions.

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

Why is Python so popular?


Python is a key programming language that leads the 4th industrial revolution with those li-
braries.th
‣ The 4 industrial revolution focuses on task automation, improved communication, and self-
monitoring of smart machines. Especially, machine learning and deep learning have been growing
rapidly as the flower of the 4th industrial revolution.
‣ As mentioned in the last slide, Python supports multiple libraries that engage in machine learning
and deep learning of artificial intelligence. It has been developing along with the progress of the 4th
industrial revolution, and it plays a key role in enhancing in their rapid growth.

Python libraries as well as frameworks enable full stack development in workplaces.


‣ Python also has different types of Python framework, such as Django, Flask, and FastAPI. With the
utilization of those frameworks and libraries, Python can be used in both front-end and back-end
programming. It allows full stack development, which is preferred in many job positions in
related industries.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 9
Introduction to Python Orientation

What is Python used for?

Artificial Intelli-
Data Science
gence Game Develop-
& Web Development
& ment
Data Visualization
Machine Learning

Simplifying everyday tasks


through automation
Automation
Software Testing ‣ Updating your grocery shopping list
Automate the sim-
and Prototyping ‣ Renaming large batches of files
ple tasks on the
computer ‣ Converting text files to spreadsheets
‣ Filling out online forms automatically and etc.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 10
Introduction to Python Orientation

How to use the C&P course?


This course is designed that students can gain a strong foundation of Python. As the core of the SIC pro-
gram, it is modularized to be effectively linked to the SIC’s other courses: AI and IoT.

By completing this course, you will be prepared to join the entry level job position that requires basic
Python skill.

IoT Course C&P Course AI Course

Basic Python

Algorithm for
Data Analysis

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 11
Introduction to Python Orientation

How to use the C&P course?


IoT Course C&P Course AI Course
Ch 1 Understand IoT
for the 4th Industrial Revo- Ch 1 Python Basic Ch 1 Introduction to AI
lution Ch 2 The Flower of Python Ba-
Ch 2 Basic Algorithm for AI Learn-
Ch 2 Raspberry Pi Hardware and sics –
ing
Electrical Electronics Sequence Data Type
Handling
Ch 3 Python Intensive – Ch 3 Practice Processing Data
Ch 3 Git and Version Control Function and Closure
Ch 4 Programming Raspberry Pi Ch 4 Probability and Statistics
Ch 4 Algorithm I – Data Struc-
ture
in Python Ch 5 Machine Learning Part 1
Ch 5 Linux for Network Connec- Ch 5 Algorithm I I– Sort
tion
Ch 6 Machine Learning Part 2
Ch 6 Programming IoT Network Ch 6 Algorithm – Graph and
Connection Others
Ch 7 Preparation for Data Analy- Ch 7 Machine Learning Part 3
Ch 7 Node.js for Internet Net- sis
work (Pandas Basics) Ch 8 Deep Learning Part 1
Ch 8 Practice of Data Analysis
Ch 8 IoT Project in Mobius Plat- and
form Data Visualization Ch 9 Deep Learning Part 2

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

 Learn the definition and necessity of computational thinking.


 Configure the basic environment for Python by installing Anaconda.
 Understand the need for a virtual environment and configure, delete, and operate the virtual environment de-
pending on the purpose of use.
 Learn the UI and instructions for Jupyter Notebook.
 Practice sequential programming characteristics using the print function.
 Learn main concepts of the Pythonic way, such as indentation, annotation, readable codes, keywords, and
variable naming conventions.
 Learn to distinguish between syntax error and runtime error.

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

Sequential Annota- Naming


Structure tion Conven-
tions

Syntax Runtime Er-


Expressions
Error ror

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

1. Real world problem


1.1. 47% of jobs will disappear in the next 20 years due to tech in-
novation.
‣ With the rapid development of computer
technology and artificial intelligence, the
professional capabilities demanded in the labor
market is changing. According to a study by
Oxford University, about 47% of jobs are
expected to be replaced by machines or
disappear within the next 20 years.
‣ Therefore, future jobs will depend more on
creativity, responsibility, and the ability to learn
through experiences, which are unique human
capabilities.
‣ The Organization for Economic Co-operation and
Development (OECD) has announced four core
competencies required for future talent.

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

1. Real world problem


1.2. The 5Cs of 21st Century Skills

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

1. Real world problem


1.3. How Should We Prepare for Computational
Thinking?
"Computational Thinking is the thought processes
involved in formulating problems and their solutions
so that the solutions are represented in a form that
can be effectively carried out by an information-pro-
cessing agent.“
- Cuny, Snyder, Wing, 2010

‣ What is computer thinking? It is to think and solve


problems like a computer scientist.
‣ It involves concepts such as algorithms, patterns,
abstraction, generalization, evaluation, and
automation.
‣ Coding is the most suitable tool for training and
practicing computational thinking.
https://www.barefootcomput-
ing.org/ ‣ Currently, many countries around the world are
adopting computer programming as alternative
education to nurture future talents (Getting part of
formal curriculum).
‣ While coding is not the only learning tool for
developing computational thinking, it is one of the
Samsung Innovation Campus best options.
Chapter 1. Programing Basic Concept and Starting Python 20
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

3 ways to make better decisions -- by thinking like a computer | Tom


Griffiths
Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 21
Mission UNIT
01

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.

Sequence Selection Iteration

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

[1] # Self-introduction program Start


Start
Print resume preface
[2] Print preface of the resume
Print name
[3] Print name

[4] Print age Print age

[5] Print job Print job

[6] Print the current address


Print current address
[7] Print birth place
Print birthplace
[9] End
End

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

use toothbrush to clean put toothpaste on tooth-


teeth brush

use toothbrush to clean


rinse toothbrush
teeth

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.

Expression Statement Program

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

#print the radius, area, and circumference of the circle


('Radius', radius)
('Area', 3.14 * radius * radius) #Apply the formula to solve for the area of a circle
#Apply the formula to solve for the circumference of the circle
('Circumference', 2.0 * 3.14 * 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.

You can create a multiple-line annotations using double quotation marks.

It allows you to make multiple lines of comments.

It allows you to make multiple lines of comments.

It allows you to make multiple lines of comments.

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

Image 1 Image 2 Image 3 Image 4 Image 5 Image6

Move One Move One Fill-In Square


Move One Move One Square Up Square Down with Color
Square Right Square Left

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

2. Virtual Environment Configuration


2.1. Definition and Necessity of Virtual Environment
When programming with Python, you will likely utilize various external packages. If you are running
multiple projects that use external packages, or if you are running a new project, you may need to update
to Pyton’s latest version or use a different type/version of packages. In such case, managing modules or
version control becomes difficult and compatibility problems may arise between versions.
For this reason, we will learn how to build a virtual environment. Python's virtual environment is a tool
that creates an independent space to manage projects and its modules and versions. In other words, it
creates various workspaces on one server/computer.
For example, on the virtual environment called “data science” on the left, you may use python 3.7. On the
“python work” space on the right, you may use python 3.8 and pandas as if you were using two
computers.

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

2. Virtual Environment Configuration


2.2. Creating a Virtual Environment
To build a virtual environment, run Anaconda Prompt from Windows's start menu.
Enter the command "concrete-n python_work python=3.8" in the prompt window to create a workspace
suitable for Python 3.8. You can customize the workspace name "python_work”.

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

2. Virtual Environment Configuration


2.2. Creating a Virtual Environment
Enter the command "concrete-n data_science python=3.7" in the prompt window. The name of the
workspace is "data_science," and a new workspace suitable for Python 3.7 version is created.

When the prompt "Proceeded ([y]/n)?" appears, enter y to proceed.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 44
Let’s code UNIT
01

2. Virtual Environment Configuration


2.3. Anaconda Commands for Managing the Virtual Envi-
ronment
The following commands for virtual environment may be used in the Anaconda Prompt. Virtual
environments can be created, activated, and then deactivated with the following commands.

Execution Command

See list of virtual environments conda env list

Create virtual environment conda create –n [name of a virtual environment]

conda create –clone [name of virtual environment to clone] –n [a


Clone virtual environment
new virtual environment]

Activate virtual environment conda activate [name of a virtual environment]

Deactivate virtual environment conda deactivate

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

2. Virtual Environment Configuration


2.3. Anaconda Commands for Managing the Virtual Environment
Entering "condaenvlist" command in the Anaconda Prompt will show you the list of Pyton’s virtual
environments. The default value is base, and the virtual environments you created earlier, data_science
and python_work, will appear.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 46
Let’s code UNIT
01

2. Virtual Environment Configuration


2.3. Anaconda Commands for Managing the Virtual Environ-
ment
You can move to a new workspace by using the command "conda activate data_science". The prompt’s
(base) will change into (data_science) and will inform the new workspace.

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

3. How To Use Jupyter Notebook


3.1. Running the Jupyter Notebook
There are three main ways you can run Jupyter Notebook. First, go to Windows Start menu and search
Jupyter Notebook.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 48
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.1. Running the Jupyter Notebook
Second, select the Jupiter Notebook from the Anaconda Navigator and click the Launch button.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 49
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.1. Running the Jupyter Notebook
Third, enter the command "jupyter notbook" in Anaconda Prompt.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 50
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.2. Jupyter Notebook UI
You will find a screen below when you run Jupyter Notebook.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 51
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.2. Jupyter Notebook UI
Press the New button at the top right for a drop-down menu. Click Folder to create a new folder. When a
new folder is created, click the check box. Then, you can rename, relocate, or delete the folder. Try
renaming the folder to “Python Project.”

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 52
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.2. Jupyter Notebook UI
Enter the newly created folder then click on the New button again. Click on the Python 3 to create a new
ipynb file. ipynb stands for IPython Notebook, and IPython is an interactive work environment.
In the example below, a new ipynb file called Untitled was created under the Python Project folder.
Alternatively, you can click on the Upload button on the upper right corner to upload the ipynb file from
the computer.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 53
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.2. Jupyter Notebook UI
A green icon appear when the ipynb file is running. To end the file running, you can 1) click on the
checkbox and then click on the Shutdown button under the Files tab, or 2) click on the Shutdown button
at the bottom right corner of the Running tab. Running tab shows you the files that are currently running.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 54
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.2. Jupyter Notebook UI
When you click on the Shutdown button, the icon next to the file will turn gray. The Running tab will show
that “There are no notebooks running.
When you finish running the file, you can Rename, Move, or Download the ipynb file from the Files tab.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 55
Let’s code UNIT
01

3. How To Use Jupyter Notebook


3.2. Jupyter Notebook UI
When you click on the ipynb file called Untitled, you will be a screen where you can code. Write a code in
the input window next to "In [ ]:" and click the Run button to execute. This input window is called a cell,
and you can use the Edit tab to copy, paste, merge, or move cells.
To activate the cell line number, click "Toggle Line Numbers" on the View tab.

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.

Style Description Example


The first letter starts with a lowercase letter and uses _ (underscore) instead
Snake of spaces between words. It’s called Snake Style because the underscores hello_world
looks like snakes.
The first letter starts with a lowercase letter, and the start of the next word is
Camel capitalized instead of spacing. It’s called the Camel style because the capital helloWorld
letters in the middle looks like a camel's back.

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:

1. Generally consists of English characters, numbers, and underscores (_).


2. There should be no spaces in the middle of the text.
3. The first word must start with an English letter or an under score (_).
4. Upper and lower case letters are distinguished. For example, Count and count are different
identifiers.
5. There is no limit to the length of the identifier.
6. Keywords cannot be used as identifiers.
7. Identifiers starting with __(two underscores) refer to special attributes or use only as the name of
specific methods. Therefore, it is not used as the name of a general function or variable.

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:

Correct Identifiers Reasons

number4 Numbers can be used after starting with English characters.

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

for_loop A keyword can be used by connecting with other characters.

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:

Incorrect Identifiers Reasons

1st_variable Cannot be used because it starts with a number.

my list Cannot be used because there is a space.

global Python keywords cannot be used as identifiers.

ver2.9 A special character other than the underscore cannot be used.

num&co A special character other than the underscore cannot be used.

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

One more step


1. Runtime Error and Resolution
A example of a common runtime error is ZeroDivisionError, an error that divides numbers by zero. In
order to solve such runtime errors, exceptions can be added using try ~ except statements.
When the user correctly enters two integers as follows, the two division operations are executed
without errors as intended by the program.

('Enter two integers.').split()

('Check if the integers are correctly entered.')

Enter two integers. 10 2


10/2 = 5.0

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 76
Let’s code UNIT
01

One more step


1. Runtime Error and Resolution
If the user incorrectly enters a string instead of an integer, or causes a case where a number is
divided by zero like the second example below, the except statement will handle the exception case.

('Enter two integers.').split()

('Check if the integers are correctly entered.')

Enter two integers. 10 two


Check if the integers are correctly entered.

('Enter two integers.').split()

('Check if the integers are correctly entered.')

Enter two integers. 10 0


Check if the integers are correctly entered.

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

Pair Programming Practice


Guideline, mechanisms & contingency plan
Preparing pair programming involves establishing guidelines and mechanisms to help students pair
properly and to keep them paired. For example, students should take turns “driving the mouse.” Ef-
fective preparation requires contingency plans in case one partner is absent or decides not to partic-
ipate for one reason or another. In these cases, it is important to make it clear that the active student
will not be punished because the pairing did not work well.

Pairing similar, not necessarily equal, abilities as partners


Pair programming can be effective when students of similar, though not necessarily equal, abilities
are paired as partners. Pairing mismatched students often can lead to unbalanced participation.
Teachers must emphasize that pair programming is not a “divide-and-conquer” strategy, but rather a
true collaborative effort in every endeavor for the entire project. Teachers should avoid pairing very
weak students with very strong students.
Motivate students by offering extra incentives
Offering extra incentives can help motivate students to pair, especially with advanced students.
Some teachers have found it helpful to require students to pair for only one or two assignments.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 79
Pair programming UNIT 01

Pair Programming Practice


Prevent collaboration cheating
The challenge for the teacher is to find ways to assess individual outcomes, while leveraging the
benefits of collaboration. How do you know whether a student learned or cheated? Experts recom-
mend revisiting course design and assessment, as well as explicitly and concretely discussing with
the students on behaviors that will be interpreted as cheating. Experts encourage teachers to make
assignments meaningful to students and to explain the value of what students will learn by complet-
ing them.
Collaborative learning environment
A collaborative learning environment occurs anytime an instructor requires students to work together
on learning activities. Collaborative learning environments can involve both formal and informal ac-
tivities and may or may not include direct assessment. For example, pairs of students work on pro-
gramming assignments; small groups of students discuss possible answers to a professor’s question
during lecture; and students work together outside of class to learn new concepts. Collaborative
learning is distinct from projects where students “divide and conquer.” When students divide the
work, each is responsible for only part of the problem solving and there are very limited opportunities
for working through problems with others. In collaborative environments, students are engaged in in-
tellectual talk with each other.

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 80
Pair programming UNIT
01

Q1 Code seven lines of print() function to produce a result like below.


.
*
***
*****
*********
*****
***
*
Samsung SW Qualification Test sample
question

Samsung Innovation Campus Chapter 1. Programing Basic Concept and Starting Python 81

You might also like