Module 3 Computer Programming
Module 3 Computer Programming
Introduction /
Orientation MODULE 1
PREPARED BY:
UNIT
Introduction / Orientation
1
LESSONS COVERED
INTRODUCTION
It is important for every student to identify and inculcate the importance of the
mission, vision, and core values of the University before learning the subject matter.
Students must able to understand that the University is knowledge – generating
institution and globally recognized for excellent instruction and exists to produce highly
competent, ethical and service oriented professionals – the students of the future.
Objectives/Competencies
The objective of this lesson is to remember, understand, and provide
expectations and insights about the mission, vision, and core values of the University
and how the subject “feedback and control” can take part in these.
Pretest
The students can state their expectations and participation on the mission,
vision, and core values as well as in the subject of feedback and control.
Lesson Proper
ACTIVITY
---------------------------------------------------------------------------------------------------------------
- -----
1. Try to master and memorize the mission, vision, goals and objectives of the
University.
University Vision
Bulacan State University is a progressive knowledge-generating institution,
globally recognized for excellent instruction, pioneering research, and responsive
community engagements.
2
OOP Unit 1: Introduction / Orientation
University Mission
Bulacan State University exists to produce highly competent, ethical and
service-oriented professionals that contribute to the sustainable socio-economic
growth and development of the nation
The BulSU Ideal Graduates Attributes (BIG A) reflect the graduate’s capacity
as: a. highly and globally competent;
b. ethical and service-oriented citizen;
c. analytical and critical thinker; and
d. reflective life-long learner.
ANALYSIS
The University has been consistently producing highly professional, ethical, and
service-oriented individuals who perform well in board examinations with impressive
results consistently exceeding the National Passing Rate and become potent driving
force in the industries in the region and beyond. BulSU has recently received its ISO
9001:2015 Certification, passed the Level II Institutional Accreditation while 50
academic programs of the different Colleges are already accredited by the Accrediting
Agency of Chartered Colleges and Universities (AACCUP), Inc. This was made
possible through the persistent hard work and resolute service of its 1,138 faculty
members and 476 non-teaching personnel who relentlessly cater and furnish the
needs of our 35,958 students.
Established
4
OOP Unit 1: Introduction / Orientation
In 1907, Governor Teodoro Sandiko of Bulacan started to look for funds to put
up a trade school for his constituents. His efforts paid off when the intermediate school
became the Bulacan Trade School in 1909. The school had an American principal and
five teachers, four of whom are Americans, the so-called Thomasites.
Upon the implementation in 1918 of the Philippine Autonomy Act passed by the
U.S. Congress in 1916, the Bulacan Trade School was formally turned over to the
Filipinos with Mr. Basilio Abiado as the first Filipino principal. He was later succeeded
by Mr. Dionisio Patag. In 1920, with Mr. Juan Lopez as the principal-teacher, the
intermediate course was finally dissolved to give way for the secondary trade
curriculum. By 1926, the school offered the complete secondary trade curriculum with
Mr. Gonzalo Villaverde as the principal-teacher. Due to limited facilities at the time, the
Bulacan Trade School was sharing the use of the classrooms of Bulacan High School
(now the Marcelo H. del Pilar High School) for their related-subject classes. Mr. Isaias
P. Maclang became the principal of the school in 1931 followed by Mr. Melanio Orbeta,
who took over the position in 1938. Mr. Orbeta held the position throughout the Second
World War and until the reopening of the school in 1945 when Mr. Deogracias P. Flores
succeeded him as the principal.
In 1945, after repairing the damage suffered during the Second World War; the
school reopened with a few hand tools and materials donated by the U.S. army
stationed in the provincial capital. With the steady increase in enrollment, more
buildings were constructed. In 1949, the United States Information Service (USIS)
donated two Quonset huts, which were used as shops and classrooms. In 1951, the
two-story related subjects building was constructed with funds from the War Damage
Rehabilitation Fund, and in 1952, the one-story Girls' Trades building was built with
half of the cost of construction was donated by the school's PTA.
On June 20, 1953, the school was nationalized under R.A. NO. 908 and
became the Bulacan National Trade School. Through the assistance of the Philippine
Council for US Aid (PHILCUSA) and International Cooperation Agency (ICA) and the
National Economic Council (NEC), the school acquired much-needed office
equipment, tools, machineries and buildings.
The Bulacan National Trade School was converted into the Bulacan National
School of Arts and Trades (BNSAT) on July 1, 1957 by virtue of R.A. 1800, passed
5
OOP Unit 1: Introduction / Orientation
through the efforts of the then Congressman Florante C. Roque of the First District of
Bulacan. With its conversion, Mr. Santiago G. Roxas was appointed as its first
superintendent. During his term, the school offered the two-year post-secondary
courses with specializations in automotive, machine shop and girls' trade courses. Mr.
Roxas was the first to envision the conversion of the school into a college and
eventually into a university. Later, the name of the school was changed to Bulacan
School of Arts and Trades through legislative action. Mr. Arnulfo M. Tongio of Bacolor,
Pampanga served as Principal until 1963. He was succeeded by Mr. Leandro Jimenez
who served as the school principal until his retirement in 1973. Mr. Roxas retired in
December 1964. He was succeeded by Mr. Deogracias Flores as the second
superintendent of the school.
By virtue of Republic Act 4470, the Bulacan School of Arts and Trades (BSAT)
was converted into the Bulacan College of Arts and Trades (BCAT) on June 19, 1965.
The Board of Trustees designated Mr. Deogracias Flores as the Acting President of
the College. Upon its conversion, the college began to expand its technical and
technician course offerings by adding shop specialization and also offered the four
year Bachelor of Science in Industrial Education (BSIE) in 1967 with majors in drafting,
machine shop practice, woodworking and automotive, cosmetology, electronics and
electricity.
On September 27, 1967, Mr. Gavino M. Carpio was appointed Acting President
of the College and then full-pledged President the following year. It was during his time
that the five-year engineering programs were added to the courses offered by the
College. Upon his retirement on December 30, 1973, Dr. Antonio T. Federizo, the Vice
President for Academic Affairs, was designated Officer-in-Charge of the College and
later Acting President. He was appointed as full-fledged President on November 29,
1976. In summer of 1977, the College started offering graduate program, the Master
of Arts in Teaching with majors in technical and vocational subjects. After Dr.
Federizo's demise on November 7, 1977, Mr. Rosario Pimentel, the then Vice
President for Academic Affairs was designated as Officer-in-Charge.
On March 27, 1978, Mr. Ernesto Valencia was appointed Acting President of
the College until his retirement on November 7, 1983. Upon his retirement, Dr. Amelia
R. Horca, the College Dean, was designated as Officer- in-Charge of the College.
Upon his return after earning his doctorate degree from U.P., Dr. Rosario
Pimentel was appointed as BCAT President on November 26, 1983. Under his able
leadership, the college continued to expand its curricular offerings and develop its
facilities to meet the needs of the growing student population. The teacher education
curriculum added more major fields of specialization in secondary education. New
majors in the engineering program were also added. Doctoral program was offered
6
OOP Unit 1: Introduction / Orientation
and new majors in the master's program were introduced. His term also saw the
completion of the new three-story integrated building (now Federizo Hall), the
constructions of a new canteen, the student services building, the main gate of the
College along McArthur Highway, and the heroes park, and the renovations of shop
rooms. He relentlessly enlisted the support of the parents and the national and local
political leaders for the conversion of the College into a university.
On December 30, 1993, Dr. Pimentel's efforts bore fruit, when President Fidel
V. Ramos signed House Bill 461 into law, known as Republic Act 7665, which
converted the Bulacan College of Arts and Trades into the Bulacan State University,
with him as the first BSU President.
The Pimentel administration made bold and decisive moves to achieve higher
levels of excellence in educational services of the institution. In 1997, beginning with
the teacher education and engineering programs, the University submitted itself for
voluntarily accreditation by the Accrediting Agency of Chartered Colleges and
Universities in the Philippines (AACCUP). In July of 2007, the AACCUP granted Level
3 accreditation status to the elementary, secondary and industrial education programs
of the College of Education. These were the first education programs that have been
granted such accreditation status the highest so far among the public higher education
institutions in Region 3. To date, most of the Programs of the University have at least
Level Il accredited status and gearing for Level 3 as well.
In 2002, a landmark agreement between the University and the Integrated Bar
of the Philippines, Bulacan Chapter, was made to establish the BSI-J - Marcelo H. Del
Pilar College of Law. Subsequently, the Marcelo H. Del Pilar Law Foundation, Inc. was
7
OOP Unit 1: Introduction / Orientation
created to support the program of the college. The Technical Panel for Legal
Education of the Commission on Higher Education hailed this move as innovative -
the first of its kind in the Philippines. The first batch of graduates of the college who
took the 2006 Bar Examinations garnered an impressive passing average of 42.8
percent, which was much higher than the national passing average of 30.6 percent.
With this performance, the statistical data issued by Supreme Court placed the BSU -
Marcelo H. Del Pilar College of Law in number 16 in the ranking of the 103 colleges
of law in the country that participated in the said examinations. Since June 2009,
when the Marcelo H. Del Pilar Law Foundation, Inc. left to the University the sole
responsibility to run its law program, the college was renamed BSU College of Law.
Global Participation
The new millennium saw Bulacan State University going global and
participating in cross-border education with other Asian countries such as South
Korea, Peoples Republic of China, Taiwan, Hong Kong, Singapore, and Malaysia. The
University signed agreements with educational institutions in these countries for the
offering of various programs of the BSU especially the doctoral and master's programs.
The University, in partnerships with Korean institutions, also hosts Korean students
for their English language course. These programs paved the way for the on
going students and faculty exchanges and visitations with those institutions abroad.
(Source: https://www.bulsu.edu.ph/about/history)
You may see the link below to understand and realize that there is a Student
Law that every student should obey. Please see the link below to know about the
student guidelines and protocols of a good student.
(https://www.bulsu.edu.ph/downloads/files/student_handbook.pdf
) Course Syllabus
This is the course outline of the subject that you will take up in the whole semester. The
syllabus content is based upon the subject and time of the class and the length of the
discussion. It also contains activities, laboratory exercises, assignments and grading
systems. The syllabus will be given upon the start of the class. And every subject has its
own syllabus.
8
OOP Unit 1: Introduction / Orientation Activity 1.1
➢ Go to https://www.bulsu.edu.ph/
➢ Look for the vision, mission and core values of BulSU.
➢ Read about the history of BulSU
➢ Write a 5-paragraph statement about the importance of the Mission, Vision
and Core Values to the development of a University. Also, include how
BulSU manage to SOAR to its current state.
➢ What do you think is the focus of the 25 aspirations for the BulSU?
ABSTRACTION
Activity 1.2
➢ Make a comparison of the Vision and Mission between BulSU and other
Universities and write their similarities and differences.
University Vision Mission Similarity Differences
BulSU
University 1:
_____________________
University 2:
_____________________
APPLICATION
Activity 1.3 – Answer the following questions.
1. What is the importance of a Vision and Mission to a University?
2. Without looking at the notes, write down the Vision, Mission and
Core Values of BulSU.
3. Still, without looking at the notes, write at least 5 out of the 25
aspirations for BulSU
Reflection/Learning Insights
Please fill in the following details for the assessment of what you have
learned.
Name (LN,FN,MI) Means of Contact Info. Date and Time
Communicatio
n (Chat, Text,
Call)
9
OOP Unit 1: Introduction / Orientation
Post-test
Name (LN,FN,MI) Year/Section Activity No. Grade / Score
1.1
1.2
1.3
Average Score
Final Requirement
Name (LN,FN,MI) Year/Section Chapter Grade
Other Parts
SUGGESTED READINGS AND WEBSITES
https://www.bulsu.edu.ph/about/history
https://www.bulsu.edu.ph/about/
https://www.bulsu.edu.ph/
10
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
MODULE 2
PREPARED BY:
UNIT
LESSONS COVERED
INTRODUCTION
This module covers the following lessons; First, review of the previous
programming language algorithm, pseudocode, and the use of flowchart. Second is
understanding the ABC’s of programming language concepts. Third, the brief history
of python and its basic functions. The last one is the start of programming using python
language.
12
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
INTRODUCTION
A program is a set of instructions that tell the computer to do things differently;
sometimes the instruction it needs to perform depends on what happens when the
previous instruction was given. Flowcharts are written from the top of a page to the
bottom, with program flow. That command is put in the correct shape box and arrows
are used to guide flow of the program. Pseudocode is a tool by which computer
algorithms are represented using a combination of natural language and
programming.
OBJECTIVES
When you finish this Lesson, you will be able to:
• Recall the concept of different steps in solving problem
• Write algorithm using pseudo code and flowchart to solve problems; and •
Acquire simple problem-solving skills.
PRE-TEST
How about we assess your insight into the exercise by responding to the
accompanying questions:
1. What are the different steps in solving problems?
2. Write pseudo code that reads two numbers and multiplies them together and print out
their product.
13
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Analysis
In order to better understand our lesson, you need to analyze and reflect on
your previous activities.
1. The above activities made me discover
______________________________________________________________
______________________________________________________________
______________________________________________________________ 2.
It helped me understand and assess that
______________________________________________________________
______________________________________________________________
______________________________________________________________ 3.
Now, I want to try and examine more on
______________________________________________________________
______________________________________________________________
______________________________________________________________
14
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Abstraction
A typical programming task can be divided into two phases:
➢ Problem solving phase
a. produce an ordered sequence of steps that describe solution of
problem
b. this sequence of steps is called an algorithm
➢ Implementation phase
a. implement the program in some programming language
Steps in Problem Solving
➢ First produce a general algorithm (one can use pseudocode) ➢ Refine
the algorithm successively to get step by step detailed algorithm that is
very close to a computer language.
➢ Pseudocode is an artificial and informal language that helps
programmers develop algorithms.
➢ Pseudocode is very similar to everyday English.
Algorithm
15
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
c. Loop (Repetition) - The repetition/loop structure is the construct where
statements can be executed repeatedly until a condition evaluates to TRUE or
FALSE.
Example 1: An algorithm in adding two numbers.
1. Start
2. Declare variables num1, num2 and sum.
3. Read values num1 and num2.
4. Add num1 and num2 and assign the result to sum.
sum←num1+num2
5. Display sum
6. Stop
Pseudocode
16
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Flowchart
17
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
(a) In drawing a proper flowchart, all necessary requirements should be listed out in
logical order.
(b) The flowchart should be clear, neat and easy to follow. There should not be any
room for ambiguity in understanding the flowchart.
(c) The usual direction of the flow of a procedure or system is from left to right or top
to bottom.
(d) Only one flow line should come out from a process symbol.
or
18
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
(e) Only one flow line should enter a decision symbol, but two or three flow lines,
one for each possible answer, should leave the decision symbol.
(f) Only one flow line is used in conjunction with terminal symbol.
(g) Write within standard symbols briefly. As necessary, you can use the annotation
symbol to describe data or computational steps more clearly.
(i) Ensure that the flowchart has a logical start and finish.
numbers
19
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
2. Write an algorithm that will read the two sides of a rectangle and calculate its
area.
20
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
21
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
REFLECTION/LEARNING INSIGHTS
Write your insights from our lessons and activities in order to evaluate knowledge
and skills that you learned.
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
22
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
INTRODUCTION
Several programming languages are implemented each year, but few
languages are becoming very popular that may be used in a career by a professional
programmer.
Programming languages are used to control computer or machine
performance. Computer programmers currently have many options to choose what
kind of language to use but there are a lot of differences between programming
languages.
Thus, this lesson will provide useful information about what are the different
types of programming languages, differences between programming languages and
programming language types.
OBJECTIVES
When you finish this lesson, you will be able to:
• Learn about useful programming languages
• Understand theoretical concepts in programming languages
• Become a better programmer in your own programming language
PRE-TEST
How about we assess your insight into the exercise by responding to the
accompanying questions:
1. What are the concepts of different programming languages?
23
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
______________________________________________________________
______________________________________________________________
______________________________________________________________
Analysis
In order to better understand our lesson, you need to analyze and reflect on
your previous activities.
1. The above activities made me discover
______________________________________________________________
______________________________________________________________
Abstraction
What is a Program?
Program is a common computer term that can be used as both a noun and a
verb. A program (noun) is executable software that runs on a computer. It is like a
script but is often much larger in size and does not require a scripting engine to run.
Instead, a program consists of compiled code that can run directly from the computer's
operating system.
24
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
A
Array is a group of related data values (called elements) that are grouped together.
All the array elements must be the same data type.
Program used to convert or translate programs written in assembly code to
machine code. Some users may also refer to assembly language or assembler
language as assembler.
B
Bitwise operators are used in programming for operating on the individual bits of
binary values.
A bug is a general term used to describe any unexpected problem with hardware or
software.
C
Code, which can be short for source code, is a term used to describe text that is written
using the protocol of a particular language, such as C, Java, Perl, PHP, or other
programming language by a computer programmer.
A compiler reads the whole source code and translates it into a complete machine
code program to perform the required tasks which is output as a new file.
Computer Program
• A program is a set of instructions following the rules of the chosen language. •
Without programs, computers are useless.
• A program is like a recipe.
• It contains a list of ingredients (called variables) and a list of directions (called
statements) that tell the computer what to do with the variables.
25
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
D
Debug refers to the process of examining and removing errors from a program's
source code.
F
A floating-point is a variable type that is used to store floating-point number values.
Examples of floating-point numbers are 1.23, 87.425, and 9039454.2.
G
Generations of Programming Language
• The first-generation languages, or 1GL, are low level languages that are machine
language.
• The second-generation languages, or 2GL, are also low-level languages that
generally consist of assembly languages.
• The third-generation languages, or 3GL, are high level languages such as C. •
The fourth-generation languages, or 4GL, are languages that consist of statements
like that in a human language. Fourth generation languages are commonly used in
database programming and scripts.
• The fifth-generation languages, or 5GL, are programming languages that contain
visual tools to help develop a program. A good example of a fifth-generation
language is Visual Basic.
A GUI is a graphical (rather than purely textual) user interface to a computer.
Elements of a GUI include textboxes, buttons, pull down menus, list and combo
boxes.
H
A high-level language is a computer programming language that isn't limited by the
computer, designed for a specific job, and is easier to understand. It is more like human
language and less like machine language.
I
Interpreter is a program that executes instructions written in a high-level language.
An interpreter reads the source code one instruction or line at a time, converts this line
into machine code and executes it.
L
A loop describes the process of a software program or script repeats the same
instructions or processes the same information over and over until receiving the order
to stop.
26
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
N
Null defines a lack of value.
O
Object-oriented programming (OOP) is a programming language model organized
around "objects" rather than "actions" and data rather than logic. Historically, a
program has been viewed as a logical procedure that takes input
P
A programmer is someone who writes computer program. Computer programmers
write, test, and maintain programs or software that tells the computer what to do.
S
The source code consists of the programming statements that are created by a
programmer with a text editor or a visual programming tool and then saved in a file.
V
A variable is a location capable of storing temporary data within a program. A void
can refer to a data type or object used in computer programming that does not have
a return a value or type.
Application
Just learn about the different language concepts in programming. To improve
their programming knowledge, here is an activity below that meets the requirements.
27
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
28
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
REFLECTION/LEARNING INSIGHTS
To evaluate the knowledge and skills of this lesson, answer the following
question: 1. What is computer program?
______________________________________________________________
______________________________________________________________
______________________________________________________________
29
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
INTRODUCTION
In this lesson, you will be guided and introduced to what Python language is,
its brief history, and as well as their applications. You must understand its basics first
since it is one of your first step in creating programs that you might encounter and use
in the future. Learning how it works will give you a better scope of where you will be
heading at.
OBJECTIVES
At the end of this chapter, you will be able to:
✓ Learn the brief history of Python.
✓ Know the features of Python.
✓ Identify the different applications of Python.
✓ Remember the four reasons to choose Python as 1st Language in
programming.
PRE-TEST
Let’s us find out how much you already know about this topic. Please answer
the following questions. You may search the web or the previous lessons as reference
to your answer.
1. What is Object Oriented Programming?
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
2. What is a programming language?
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
30
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
31
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Fun fact. It wasn't named after a dangerous snake. Rossum was fan of a comedy
series from late seventies. The name "Python" was adopted from the same series
"Monty Python's Flying Circus".
History of Python
▪ Python was conceptualized by Guido Van Rossum in
the
late 1980s.
▪ Rossum published the first version of Python code
(0.9.0)
in February 1991 at the CWI (Centrum Wiskunde &
Informatica) in the Netherlands, Amsterdam.
▪ Python is derived from ABC programming language,
which
is a general-purpose programming language that had been
developed at the CWI.
▪ Rossum chose the name "Python", since he was a big fan of Monty Python's
Flying Circus.
▪ Python is now maintained by a core development team at the institute,
although Rossum still holds a vital role in directing its progress.
Release Dates of Different Versions
Version Release Data
Features of Python
1. Easy to learn, easy to read and easy to maintain.
2. Portable: It can run on various hardware platforms and has the same interface
on all platforms.
32
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Applications of Python
33
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
IV, and more. It’s also widely used for penetration testing, data analysis, scientific
computing, and more.
• Python jobs pay well, and python programmers are in high demand.
Hybrid Language:
• Prototyping is faster.
• Portable
35
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Abstraction
After reading and learning the lesson, let us summarize up:
What is Python?
Python is a high-level programming language which is:
▪ Interpreted: It is processed at runtime by the interpreter.
▪ Interactive: You can use a Python prompt and interact with the interpreter
directly to write your programs.
▪ Object-Oriented: It supports Object-Oriented technique of programming. ▪
Beginner’s Language: A great language for the beginner-level
programmers and supports the development of a wide range of
applications.
36
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
• C++ - 9.9%
2017 - #1 in The 9 Most in-demand Programming Language.
• #2 - c++
• #4- java
2018 - Percentage growth of Python is 500 times more than it’s peer Languages.
• Python - 57.36%
• Java -37.09 %
2019 - Data job mentioning this skill set / skill set over the previous
year • Java - 6.62 - 63.30%
37
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
REFLECTION/LEARNING INSIGHTS
In order to evaluate knowledge and skills, you learned from our lessons and
activities, write a brief insight below.
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
38
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
INTRODUCTION
In this lesson, you will start coding and debugging Python, you will be guided
in writing basic codes and providing simple output using it. The lesson will also tackle
how to use comments, prompts and reserved words as well as lines and indention.
OBJECTIVES
At the end of this chapter, you will be able to:
✓ Learn the two approach of programming.
✓ Know the reserved words.
✓ Create comments.
✓ Identify multiple statements on a single line.
PRE-TEST
Let’s us find out how much you already know about this topic. Please answer
the following questions. You may search the web or the previous lessons as reference
to your answer.
▪ Python was conceptualized by Guido Van ___________ in the late 1980s. ▪
Rossum published the first version of Python code (0.9.0) in ____________
1991 at the CWI (Centrum Wiskunde & Informatica) in the Netherlands ,
Amsterdam.
▪ Python is derived from _________ programming language, which is a general-
purpose programming language that had been developed at the CWI. ▪ Rossum
chose the name "Python", since he was a big fan of _____________ Flying
Circus.
▪ _____________ is now maintained by a core development team at the
institute, although Rossum still holds a vital role in directing its progress. ▪
____________: It can run on various hardware platforms and has the same
interface on all platforms.
▪ ____________:: You can add low-level modules to the Python interpreter. ▪
____________:: Python provides a good structure and support for large
programs.
▪ Python has support for an ____________: mode of testing and debugging. ▪
Python has a broad standard ____________: cross-platform.
▪ Everything in Python is an ____________:: variables, functions, even code.
Every object has an ID, a type, and a value.
▪ Python provides interfaces to all major commercial ____________:. ▪ Python
supports functional and structured programming methods as well as
____________:.
39
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
So, in this method, each and every module is built and tested at an individual
level (unit testing) prior to integrating them to build a concrete solution. The unit testing
is performed by leveraging specific low-level functions.
What Are The Key Differences Between The Top-Down And The Bottom
Up Approaches?
Based on the core preferences and values of each methodology, we can chalk
out certain basic differences between the two. They are:
• While the top-down approach focuses on breaking down a big problem into
smaller and understandable chunks, the bottom-up approach first focuses on
40
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
solving the smaller problems at the fundamental level and then integrating them into
a whole and complete solution.
• The top-down approach is primarily used by structured programming languages
such as C, COBOL, Fortran. On the contrary, the bottom-up approach is preferred
by OOP languages such as C++, C#, Python, Java, and Perl.
• In the top-down approach, each module and submodule are processed separately,
and hence, they might contain redundant information. However, the bottom-up
approach relies on data encapsulation and data-hiding, thereby, minimizing
redundancy.
• The top-down approach doesn’t require the modules to have a well-established
line of communication among them, whereas, in the bottom-up approach, the
modules must have a certain degree of interaction and communication among them.
• While the top-down approach can be used in module documentation, debugging,
and code implementation, the bottom-up approach is primarily used in testing.
Thus, in conclusion, we can say that the top-down approach is rather the
conventional method that seeks to decompose a complex problem into smaller
fragments (from high-level specification to low-level specification), the bottom-up
approach works is just the opposite – it first concentrates on designing the
fundamental components of an algorithm and then moves up to a higher level to
achieve a complete result.
Interactive Programming – One should open the python program via command
prompt (windows) or terminal (other OS) after installed. To invoke interpreter w/o
passing script file/source code as a parameter, one should meet the following
prompt.
41
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Example 2: print in
python 3.8.5
Type the following text at the Python prompt and press Enter: print (“Hello,
Python!”) and “Example 2” above will be the result.
Example 3: print in
python 2.7.14
If you are running Python 2, print “Hello, Python!”; will be the code to run will
have same result as “Example 2” but would render error if same syntax on Python 2
was used as the “Example 2” above.
Example 4: error
in syntax in python 3.8.5
Script Mode Programming – One should create a file having extension name of “.py”
that has “print “Hello, Python!” code in it. And put it on any location on your pc.
Technically, we saved “test.py” file on Users folder where it has the said code.
42
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Reserved Words
Reserved words (also called keywords) are defined with predefined meaning
and syntax in the language. These keywords have to be used to develop programming
instructions. Reserved words can’t be used as identifiers for other programming
elements like name of variable, function etc.
Class From or
43
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Continue global pass
Def If raise
elif In True
else Is try
Python 3 has 33 keywords while Python 2 has 30. The print has been
removed from Python 2 as keyword and included as built-in function.
Python Indention
Indentation is one of the most important logic part of the program in different
languages esp. Python, it uses whitespace (spaces and tabs) to define program blocks
whereas other languages like C, C++ use braces ({}) to indicate blocks of codes for
class, functions or flow control. The number of whitespaces (spaces and tabs) in the
indentation is not fixed, but all statements within the block must be the indented same
amount. In the following program, the block statements have no indentation.
This is the proper way to implement Indentation, there is a condition before the
print(“Hello World”), it will become the output of the given condition that’s why the
Indention is very important part of the program.
Example 7: Sample Code with indentation
45
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Example 9: Lines and Indentation
Multi-line Statements
Statements in Python typically end with a new line. Python does, however,
allow the use of the line continuation character (\) to denote that the line should
continue.
Example 10: using continuation character ( \ )
Statements contained within the [], {}, or () brackets do not need to use the line
continuation character.
Example 11: using the square bracket ([ ])
Python does not really have a syntax for multiline comments. To add a
multiline comment, you could insert a # for each line:
46
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
sample code:
#This is a comment
#written in
#more than just one line
print("Hello, World!")
Or, not quite as intended, you can use a multiline string (Docstrings). Python
will ignore string literals that are not assigned to a variable, you can add a multiline
string (triple quotes) in your code, and place your comment inside it:
sample code:
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")
Quotation in Python
>>> var1='hello'
>>> var1
'hello'
>>> var2="hello"
>>> var2
'hello'
>>> var3='''hello'''
>>> var3
'hello'
>>> var4="""hello"""
>>> var4
'hello'
If it is required to embed double quotes as a part of string, the string itself should
be put in single quotes. On the other hand, if single quoted text is to be embedded,
string should be written in double quotes.
47
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
>>> var2="Welcome to 'Python training' from Tutorialspoint"
>>> var2
"Welcome to 'Python training' from Tutorialspoint"
Python string functions are very popular. There are two ways to represent
strings in python. String is enclosed either with single quotes or double quotes. Both
the ways (single and double quotes) are correct depending upon the requirement.
Sometimes we must use quotes (single or double quotes) together in the same string,
in such cases, we use single and double quotes alternatively so that they can be
distinguished.
Explanation- It gives an invalid syntax error. Because single quote after “it” is
considered as the end of the string and rest part is not the part of a string.
Comments
Python has commenting capability for the purpose of in-code
documentation. ➢ Comments can be used to explain Python code.
➢ Comments can be used to make the code more readable.
➢ Comments can be used to prevent execution when testing code.
48
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
them:
Or, not quite as intended, you can use a multiline string (Docstrings). Python
will ignore string literals that are not assigned to a variable, you can add a
multiline string (triple quotes) in your code, and place your comment inside it:
If the string is not assigned to a variable, Python will read the code, but then
ignore it, and you have made a multiline comment.
49
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
NOTE:
➢ x/y is a variable which will get the string value, typed by user during the
execution of program.
➢ Typing of data for the raw_input() function is terminated by enter key.
➢ We can use raw_input() to enter numeric data also.
50
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Definition and
Usage
How the input function works in Python :
➢ When input() function executes program flow will be stopped until the user has
given an input.
➢ The text or message display on the output screen to ask a user to enter input
value is optional i.e. the prompt, will be printed on the screen is optional. ➢ A
prompt is a string, representing a default message before the input. ➢ Whatever
you enter as input, input function converts it into a string. if you enter an integer
value still input() function convert it into a string. You need to explicitly convert it
into an integer in your code using typecasting.
Suites
A group of individual statements, which make a single code block are called suites
in Python. Compound or complex statements, such as if, while, def, and class require
a header line and a suite.
Header lines begin the statement (with the keyword) and terminate with a colon ( : )
and are followed by one or more lines which make up the suite. If expression:
#Suite / code block
Elif expression:
#Suite / code block
Else:
#Suite / code block
Code #code outside If-Elif condition
52
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Analysis
After learning its history and basic functions, let us have a deeper
understanding in coding Python.
Python Line Structures
A physical line is a sequence of characters terminated by an end-of-line sequence.
In windows it is called CR LF or return followed by a linefeed and in Unix, it is called
LF or linefeed. A line contains only spaces, tabs, form feeds possibly a comment is
known as a BLANK LINES, and Python interpreter ignores it. A Python program is
divided into a few logical lines and every logical line is terminated by the token
NEWLINE. A logical line is created from one or more physical lines.
53
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
54
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
Quotation in Python
Python accepts single ('), double (") and triple (''' or """) quotes to denote
string literals, as long as the same type of quote starts and ends the string. The
triple quotes are used to span the string across multiple lines. Example 28.
Quotation in Python
Python Comments
Comments start with the hash (#) character in Python. All character or symbols
after the hash symbol are considered part of the comment. The comment is not the
part of the main program, but it is a helping tool in every program to know how a block
of codes functions because comments are meant to explain code.
The Python Comment is a programmer-readable explanation or annotation in
the source code of a computer program. Comments are text notes added to the
program to provide explanatory information about the source code. They are used in
a programming language to document the program and remind programmers of what
tricky things they just did with the code and also help the later generation for
understanding and maintenance of code. The compiler considers these as non-
55
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
A documentation string is a literal string that can put as the first statement in a
function, module, class, or method definition. Different from a regular comment,
documentation string can be accessed at run-time using obj.__doc__ attribute where
obj is the name of function, module or class, etc. Documentation string is also used to
generate documentation automatically. Documentation string is also known as
docstrings. Python provides two kinds of docstrings: one-line docstrings and multi-line
docstrings.
One-line docstrings
One-line docstring fits in one line begins with triple quotes and ends with triple
quotes. There should not have a blank line either before or after the one-line
docstring.
c. Python multiline comments.
As its name implies, multi-line docstring can span multiple lines. Just like one
line docstring, the first line of multi-line docstring is a summary, followed by a blank
line and of course more descriptions underneath.
56
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
When the program is getting bigger and more complicated, it is getting difficult
to read and maintain. For these reasons, it is a good practice to put some
documentations or notes into your code. These notes are called comments.
The code only can tell you how it does but cannot tell you why it does so.
However, your comment can do that. You use comments to explain the formulas,
complex algorithms and sophisticated business logic.
Python comment begins with a hash or pound (#) sign and continues to the end
of the line. It is important to note that Python interpreter ignores comments when it
interprets the code.
You use a block comment to explain the code that follows it. A block comment
is indented at the same level as the code block. To write a block comment, you start
with a single hash (# ) sign followed by a single space and comment.
57
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
A documentation string is a literal string that you put as the first statement in a
function, module, class, or method definition. Different from a regular comment,
documentation string can be accessed at run-time using obj.__doc__ attribute where obj
is the name of function, module or class, etc.
One-line docstrings
One-line docstring fits in one line begins with triple quotes and ends with triple
quotes. There should not have a blank line either before or after the one-line
docstring.
Multi-line docstrings
As its name implies, multi-line docstring can span multiple lines. Just like one
line docstring, the first line of multi-line docstring is a summary, followed by a blank
line and of course more descriptions underneath.
Python does not support multiline comments like C/C++ or Java. However,
there is nothing to stop you to use multi-line docstrings as multiline comments. This is
also mentioned by Guido van Rossum, the creator of Python.
It is important to keep you comment clear, concise and explanatory. The goal
is to save time and energy for maintenance developers who will work on the code.
REFLECTION/LEARNING INSIGHTS
In order to evaluate knowledge and skills, you learned from our lessons and
activities, write a brief insight below.
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
58
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
After finishing the lesson and answer problems and activities given from the start. For
your activity to be recorded, you pass it on time and please fill up the following details:
Name (LN,FN,MI) Year/Section Activity No. Grade / Score
Average Score
POST-TEST
59
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
REFERENCES
LESSON 1
LESSON 2
➢ (2015, January 8). Python Tip: Validating user input as number (Integer) | 101
.... Retrieved August 14, 2020, from https://www.101computing.net/number
only/
60
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
LESSON 3
➢ https://www.zentut.com/python-tutorial/python-comments/
➢ https://en.wikipedia.org/wiki/Python_(programming_language) ➢
https://www.tutorialspoint.com/What-are-different-types-of-quotes-in-Python ➢
https://towardsdatascience.com/single-double-and-triple-quotes-in-python
7ceea990baf
➢ https://stackoverflow.com/questions/9050355/using-quotation-marks-inside
quotation-marks
➢ https://realpython.com/python-comments-guide/
GLOSSARY
docstring - A string that appears as the lexically first expression in a module, class
definition or function/method definition is assigned as the __doc__ attribute of the
object where it is available to documentation tools or the help() built-in function.
61
OOP Unit 2: Review, Programming Concepts, Basic of Python and Programming
interactive - Python has an interactive interpreter which means you can enter
statements and expressions at the interpreter prompt, immediately execute them and
see their results.
interpreted - Python is an interpreted language, as opposed to a compiled one,
though the distinction can be blurry because of the presence of the bytecode
compiler. object - Any data with state (attributes or value) and defined behavior
(methods). object oriented - Programming typified by a data-centered (as opposed
to a function centered) approach to program design.
triple-quoted string - A string that is bounded by three instances of either the double
quote mark (") or the single quote mark (').
type - A "sort" or "category" of data that can be represented by a programming
language.
whitespace - The unconventional use of space characters (' ') to control the flow of a
program.
ANSWER KEY
c 10.
9.a
8.a
7.b
6.a
5.d
4.b
3.d
2.d
1.b
62