Computer10.q3module - Reso
Computer10.q3module - Reso
BRIEF INTRODUCTION:
Hello dear students! Welcome to the second quarter of the school year. I hope your enthusiasm and excitement got more ignited
and challenged to our new mode of learning amidst this COVID-19 outbreak. In our computer class, we will focus on basic flowchart
designing. In this subject, your prior knowledge in your previous computer classes will still be used for you to be able to cope with
given tasks/ activities. I hope you will enjoy our lessons! Thus, in this second quarter learning module, you are expected to acquire the
essential knowledge and develop the basic skills prescribed by DepEd’s learning standards aligned with the MELCs as shown in the
table below. God bless and let’s get into it!
21st Century Learning Skills Creativity, Critical Thinking, Collaboration, Career Learning, Cross-cultural
Understanding, Computer Technology, Communication
Core Values Academically Excellent, Social Responsibility, Community Building, Christian
Witnessing
INTRODUCTION:
In this Python tutorial for beginners, you will learn Python programming basics and advanced concepts. This Python course
contains all the Python basics from installation to advanced stuff like Python data science. This Python programming tutorial helps
you to learn Python free with Python notes and Python tutorial PDF. These Python tutorials will help you learn the basics of
Python.
CONTENT DISCUSSION:
Python is an interpreted, object-oriented, high-level programming language. It has high-level built-in data structures with
dynamic typing and binding.
Python’s syntax is easy to learn. The Python interpreter and standard library are available without charge for all major
platforms can be freely distributed.
Programmers use python because it increases productivity. Since there is no compilation step, the edit-test-debug cycle is
fast and effective. The quickest way to debug a program is to add a few print statements to the source.
PyCharm is a cross-platform editor developed by JetBrains. Pycharm provides all the tools you need for productive Python
development.
Below are the detailed steps for installing Python and PyCharm
Step 1) To download and install Python, visit the official website of Python https://www.python.org/downloads/ and choose your
version. We have chosen Python version 3.6.3
1
Step 2) Once the download is completed, run the .exe file to install Python. Now click on Install Now.
Step 4) When it finishes, you can see a screen that says the Setup was successful. Now click on “Close”.
2
How to Install Pycharm
Here is a step by step process on how to download and install Pycharm IDE on Windows:
Step 1) To download PyCharm visit the website https://www.jetbrains.com/pycharm/download/ and Click the “DOWNLOAD” link
under the Community Section.
Step 2) Once the download is complete, run the exe for install PyCharm. The setup wizard should have started. Click “Next”.
Step 3) On the next screen, Change the installation path if required. Click “Next”.
3
Step 4) On the next screen, you can create a desktop shortcut if you want and click on “Next”.
Step 5) Choose the start menu folder. Keep selected JetBrains and click on “Install”.
4
Step 7) Once installation finished, you should receive a message screen that PyCharm is installed. If you want to go ahead and run it,
click the “Run PyCharm Community Edition” box first and click “Finish”.
Step 8) After you click on “Finish,” the Following screen will appear.
5
Step 2) You will need to select a location.
1. You can select the location where you want the project to be created. If you don’t want to change location than keep it as it is
but at least change the name from “untitled” to something more meaningful, like “FirstProject”.
2. PyCharm should have found the Python interpreter you installed earlier.
3. Next Click the “Create” Button.
Step 3) Now Go up to the “File” menu and select “New”. Next, select “Python File”.
6
Step 4) A new pop up will appear. Now type the name of the file you want (Here we give “HelloWorld”) and hit “OK”.
Step 6) Now Go up to the “Run” menu and select “Run” to run your program.
Step 7) You can see the output of your program at the bottom of the screen.
Step 8) Don’t worry if you don’t have Pycharm Editor installed, you can still run the code from the command prompt. Enter the
correct path of a file in command prompt to run the program.
7
Python print() function
The print() function in Python is used to print a specified message on the screen. The print command in Python prints strings or
objects which are converted to a string while printing on a screen.
Syntax:
print(object(s))
Example: 1
To print the Welcome to Guru99, use the Python print statement as follows:
Output:
Welcome to Guru99
print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")
Output:
USA
Canada
Germany
France
Japan
Example:
Let us print 8 blank lines. You can type:
print (8 * "\n")
8
or:
print ("\n\n\n\n\n\n\n\n\n")
Output
Welcome to Guru99
Welcome to Guru99
Example 1:
Welcome to Guru99!
Example 2:
9
Step 8) Don’t worry if you don’t have Pycharm Editor installed, you can still run the code from the command prompt.
Enter the correct path of a file in command prompt to run the program.
Most Essential Learning Know how to use keywords and identifies in Python programming, Use indents
Competencies (MELCs) and comments to describe the different parts of the program, Learn the standard
formatting in Python
CONTENT DISCUSSION:
Python Keywords
Keywords are predefined, reserved words used in Python programming that have special meanings to the compiler.
We cannot use a keyword as a variable name, function name, or any other identifier. They are used to define the syntax and structure
of the Python language.
Keywords are case-sensitive. That is why we must be careful when writing or typing them.
There are 33 keywords in Python (specially in versions 3.3 and above), and this number may change slightly in time. (This
happens when there are updates in the program.)
All the keywords except True, False and None are in lowercase and they must be written as they are.
Python Identifiers
Identifiers are the name given to variables, classes, methods, etc. For example,
language = 'Python'
10
Here, language is a variable (an identifier) which holds the value 'Python'.
We cannot use keywords as variable names as they are reserved names that are built-in to Python. For example,
continue = 'Python'
The above code is wrong because we have used continue as a variable name. To learn more about variables, visit Python Variables.
score @core
return_value return
name1 1name
Keywords are the reserved words in Python. They are in lowercase except for True, False, and None.
Identifiers are the names given to entities like classes, functions, variables, etc. in Python. They help differentiate one entity from
another.
An underscore (_) or camel case (camelCase) are used to separate multiple words.
A variable should have name that is close to the value it holds.
CONTENT DISCUSSION:
Statements
A statement is an instruction that a Python interpreter can execute. So, in simple words, we can say anything written in Python is
a statement.Python statement ends with the token NEWLINE character. It means each line in a Python script is a statement.
For example, a = 10 is an assignment statement. where a is a variable name and 10 is its value. There are other kinds of statements
such as if statement, for statement, while statement, etc., we will learn them in the following lessons.
There are mainly four types of statements in Python, print statements, Assignment statements, Conditional statements, Looping
statements.
The print and assignment statements are commonly used. The result of a print statement is a value. Assignment statements don’t
produce a result it just assigns a value to the operand on its left side.A Python script usually contains a sequence of statements. If there
is more than one statement, the result appears only one time when all statements execute.
Example
# statement 1
print('Hello')
# statement 2
x =20
# statement 3
print(x)
Output
Hello
20
As you can see, we have used three statements in our program. Also, we have added the comments in our code. In Python, we use the
hash (#) symbol to start writing a comment. In Python, comments describe what code is doing so other people can understand it.
# statement 3
print('Area of rectangle:', l * b)
Multi-Line Statements
Python statement ends with the token NEWLINE character. But we can extend the statement over multiple lines using line
continuation character (\). This is known as an explicit continuation.
12
Example
addition =10+20+ \
30+40+ \
50+60+70
print(addition)
# Output: 280
Implicit continuation:
We can use parentheses () to write a multi-line statement. We can add a line continuation statement inside it. Whatever we add inside
a parentheses () will treat as a single statement even it is placed on multiple lines.
Example:
addition =(10+20+
30+40+
50+60+70)
print(addition)
# Output: 280
As you see, we have removed the the line continuation character (\) if we are using the parentheses ().
We can use square brackets [] to create a list. Then, if required, we can place each list item on a single line for better readability.
Same as square brackets, we can use the curly { } to create a dictionary with every key-value pair on a new line for better readability.
Example:
# list of strings
names =['Emma',
'Kelly',
'Jessa']
print(names)
Output:
Indentation
Indentation refers to the spaces at the beginning of a code line.Where in other programming languages the indentation in code is for
readability only, the indentation in Python is very important.Python uses indentation to indicate a block of code.
A code of block starts with indentation and ends with first unindented line.The amount if indentation is up to us, but we make sure that
it is consistent throughout that block.
Four (4) spaces are used for indentation and is preferred over using tabs.
13
In the above block of code, the indentation is used after the “if” and “else” statement so that the Python interpreter can execute the
print statement and gives the proper output; else if it is not properly indented, then it would throw us an error which is seen in below
output. The print statement (“ n is greater than 5” ) and the print statement ( “ n is not greater than 5” )are two different clocks of code.
To indicate these blocks of code, Python uses indentation at the beginning of each line of the block with the same number of spaces
that are 4 spaces.
Comments
In computer programming, comments are hints that we use to make our code more understandable.
Comments are completely ignored by the interpreter. They are meant for fellow programmers. For example,
14
Single-line Comment in Python
A single-line comment starts and ends in the same line. We use the # symbol to write a single-line comment. For example,
# create a variable
name = 'Eric Cartman'
Eric Cartman
We can also use the single-line comment along with the code.
Here, code before # are executed and code after # are ignored by the interpreter.
Here, each line is treated as a single comment, and all of them are ignored.
These triple quotes are generally used for multi-line strings. But if we do not assign it to any variable or function, we can use it as a
comment.
The interpreter ignores the string that is not assigned to any variable or function.
Here, the multiline string isn't assigned to any variable, so it is ignored by the interpreter. Even though it is not technically a
multiline comment, it can be used as one.
print('Python')
# print("Error Line )
15
print('Django')
Here, print("Error Line) was causing an error so we have changed it as a comment. Now, the program runs without any errors.
The commands in Python are called statements.The end of a statement is marked by a newline character.
To extend statements over multiple lines, we use the backslash (\).
Line continuation is implied inside the parentheses (), brackets [], and braces {}.
Multiple statements can be put in a single line using a semi-colon (;).
Python uses indentation to define a block of code.
The amount of indentation, by default, is hour (4) spaces.
Comments describe what is going on inside a program.
To write a comment, we use the hash (#) symbol or enclose it with three (3) singlequotes(‘‘‘ ’’’), or three (3) double quotes (“““ ”””).
16
MODULE WEEKS 4-5. Declaring Variables, Constants, and Literals
Most Essential Learning Know how to use variables, constants, and literals are data that they will used in
Competencies (MELCs) programming, Work with data types and different type conversion, Realize that
knowing the type of fata that they will be using can be a very useful tool in
programming
REFERENCES:(Please be guided with the given references to help you perform the given activities. Click the given links and
hyperlinks to access the suggested learning resources.)
Printed: Cobre, E. J., Olalia, N., &Tingzon, K. (2019). ICT Tools Today High School Series Computers for Digital Learners
Grade 10 (1st ed., Vol. 1) [Book]. The Phoenix Publishing house Inc.
INTRODUCTION:
In this week’s module, you will learn about Python variables, constants, literals with the help of examples.
Directions: Fill in the K-W-H-L Chart below to assess your prior knowledge and understanding of the topic
What I Know What I Want to Find Out How I Can Learn What I Have Learned
More
SHORT EXERCISES/DRILLS:
Activity 1.Identify the Output. Identify the output of the code below. Write your answer in the box.
#What is the output?
mynie = “moe”
eenie = “mynie”
meenie = “eenie”
moe = “meenie”
print(eenie)
print(meenie)
print(mynie)
print(moe)
CONTENT DISCUSSION:
Python Variables
In programming, a variable is a container (storage area) to hold data. For example,
number = 10
17
Assigning values to Variables in Python
As we can see from the above example, we use the assignment operator = to assign a value to a variable.
print(site_name)
# Output: programiz.pro
Output
apple.com
In the above example, we assigned the value programiz.pro to the site_name variable. Then, we printed out the value assigned
to site_name
print(site_name)
Output
programiz.pro
apple.com
print(a) # prints 5
print(b) # prints 3.2
print(c) # prints Hello
If we want to assign the same value to multiple variables at once, we can do this as:
site1 = site2 ='programiz.com'
snake_case
MACRO_CASE
camelCase
CapWords
Create a name that makes sense. For example, vowel makes more sense than v.
If you want to create a variable name having two words, use underscore to separate them. For example:
my_name
current_salary
18
Python is case-sensitive. So num and Num are different variables. For example,
var num = 5
var Num = 55
print(num) # 5
print(Num) # 55
Python Constants
A constant is a special type of variable whose value cannot be changed.
In Python, constants are usually declared and assigned in a module (a new file containing variables, functions, etc which is imported to
the main file).
Let's see how we declare constants in separate file and use it in the main file,
Create a constant.py:
# declare constants
PI = 3.14
GRAVITY = 9.8
Create a main.py:
In the above example, we created the constant.py module file. Then, we assigned the constant value to PI and GRAVITY.
After that, we create the main.py file and import the constant module. Finally, we printed the constant value.
Python Literals
Literals are representations of fixed values in a program. They can be numbers, characters, or strings, etc. For example, 'Hello,
World!', 12, 23.0, 'C', etc.
Literals are often used to assign values to variables or constants. For example,
site_name = 'programiz.com'
0b101,
Binary Start with 0b .
0b11
Floating-point
10.5, 3.14 Containing floating decimal points.
Literal
19
Python Boolean Literals
There are two boolean literals: True and False.
For example,
pass = true
some_character = 'S'
print(value)
# Output: None
Here, we get None as an output as the value variable has no value assigned to it.
Literal Collections
There are four different literal collections List literals, Tuple literals, Dict literals, and Set literals.
# list literal
fruits = ["apple", "mango", "orange"]
print(fruits)
# tuple literal
numbers = (1, 2, 3)
print(numbers)
# dictionary literal
alphabets = {'a':'apple', 'b':'ball', 'c':'cat'}
print(alphabets)
# set literal
vowels = {'a', 'e', 'i' ,'o', 'u'}
print(vowels)
Output
In the above example, we created a list of fruits, a tuple of numbers, a dictionary of alphabets having values with keys designated to
each value and a set of vowels.
20
1. What are variables, constants and literals?
Variable is a named location used to store data in the memory. It has a unique name called identifier. We use the
equal (=) sign to assign the value to a variable.
A constant is a variable whose values do not change. It is usually assigned and declared on a module. They are
written in all capital letters and underscores to separate the words.
Literal is a raw data given in a variable constant.
Variable is a named location used to store data in the memory. It has a unique name called identifier. We use the equal (=) sign to
assign the value to a variable.
A constant is a variable whose values do not change. It is usually assigned and declared on a module. A module is a new file that
contains values or functions, which is imported to the main file. They are written in all capital letters and underscores to separate the
words.
Literal is a raw data given in a variable constant.
Numeric literals are unchangeable. The four (34) numerical types are: plain, integers, long integers, floating point numbers, and
imaginary numbers.
A string literal is a sequence of characters surrounded by single, double, or triple quotes.
A character literal is a single character surrounded by single or double quotes.
In computer programming, data types specify the type of data that can be stored inside a variable. For example,
num = 24
Since everything is an object in Python programming, data types are actually classes and variables are instances(object) of these
classes.
Integers, floating-point numbers and complex numbers fall under Python numbers category. They are defined
as int, float and complex classes in Python.
We can use the type() function to know which class a variable or a value belongs to.
21
num1 = 5
print(num1, 'is of type', type(num1))
num2 = 2.0
print(num2, 'is of type', type(num2))
num3 = 1+2j
print(num3, 'is of type', type(num3))
Run Code
Output
In the above example, we have created three variables named num1, num2 and num3 with values 5, 5.0, and 1+2j respectively.
We have also used the type() function to know which class a certain variable belongs to.
Since,
5 is an integer value, type() returns int as the class of num1 i.e <class 'int'>
2.0 is a floating value, type() returns float as the class of num2 i.e <class 'float'>
1 + 2j is a complex number, type() returns complex as the class of num3 i.e <class 'complex'>
Python List Data Type
List is an ordered collection of similar or different types of items separated by commas and enclosed within brackets [ ]. For example,
To access items from a list, we use the index number (0, 1, 2 ...). For example,
In the above example, we have used the index values to access items from the languages list.
languages[0] - access first item from languages i.e. Swift
languages[2] - access third item from languages i.e. Python
Tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be
modified.
In Python, we use the parentheses () to store items of a tuple. For example,
Similar to lists, we use the index number to access tuple items in Python .
For example,
# create a tuple
product = ('Microsoft', 'Xbox', 499.99)
22
# access element at index 1
print(product[1]) # Xbox
String is a sequence of characters represented by either single or double quotes. For example,
name = 'Python'
print(name)
Python
Python for beginners
Set is an unordered collection of unique items. Set is defined by values separated by commas inside braces { }.
For example,
# create a set named student_id
student_id = {112, 114, 116, 118, 115}
Output
In programming, type conversion is the process of converting data of one type to another. For example: converting integer data
to string.
There are two types of type conversion in Python.
Implicit Conversion - automatic type conversion
Explicit Conversion - manual type conversion
23
Output
Value: 124.23
Data Type: <class 'float'>
Note:
We get TypeError, if we try to add string and integer. For example, '12' + 23. Python is not able to use Implicit Conversion in
such conditions.
Python has a solution for these types of situations which is known as Explicit Conversion.
In Explicit Type Conversion, users convert the data type of an object to required data type.
We use the built-in functions like int(), float(), str(), etc to perform explicit type conversion.
This type of conversion is also called typecasting because the user casts (changes) the data type of the objects.
print("Sum:",num_sum)
print("Data type of num_sum:",type(num_sum))
Output
num_string = int(num_string)
Here, we have used int() to perform explicit type conversion of num_string to integer type.
After converting num_string to an integer value, Python is able to add these two variables.
Finally, we got the num_sum value i.e 35 and data type to be int.
Most Essential Learning Competencies Use the input, output and built-in modules
(MELCs)
CONTENT DISCUSSION:
Python Output
Here, the print() function displays the string enclosed inside the single quotation.
Syntax of print()
In the above code, the print() function is taking a single parameter.
However, the actual syntax of the print function accepts 5 parameters
Here,
object - value(s) to be printed
sep (optional) - allows us to separate multiple objects inside print().
end (optional) - allows us to add add specific values like new line "\n", tab "\t"
file (optional) - where the values are printed. It's default value is sys.stdout (screen)
flush (optional) - boolean specifying if the output is flushed or buffered. Default: False
Notice that we have included the end= ' ' after the end of the first print() statement.
Hence, we get the output in a single line separated by space.
25
Example 2: Python print() with sep parameter
print('New Year', 2023, 'See you soon!', sep= '. ')
Output
name = "Programiz"
# print literals
print(5)
# print variables
print(number)
print(name)
Output
5
-10.6
Programiz
Output
Programiz is awesome.
Here,
the + operator joins two strings 'Programiz is ' and 'awesome.'
the print() function prints the joined string
Output formatting
Sometimes we would like to format our output to make it look attractive. This can be done by using the str.format() method. For
example,
x = 5
y = 10
Python Input
While programming, we might want to take the input from the user. In Python, we can use the input() function.
Syntax of input()
input([prompt])
26
print('You Entered:', num)
Enter a number: 10
You Entered: 10
Data type of num: <class 'str'>
In the above example, we have used the input() function to take input from the user and stored the user input in the num variable.
It is important to note that the entered value 10 is a string, not a number. So, type(num) returns <class 'str'>.
To convert user input into a number we can use int() or float() functions as:
Here, the data type of the user input is converted from string to integer .
The print() function is used to display the output data on the screen.
The str.format() method is used to format the output.
The curly braces {} are used as placeholders.
The input() function is used to define value of variables.
Prompt is the string we wish to display on the screen.
A module contains the Python definitions and statements.
Definitions inside a module can be imported to another module or the interactive interpreter in Python.
Most Essential Learning Competencies Learn to use assignment operators to assign the specific data to its container
(MELCs)
REFERENCES:(Please be guided with the given references to help you perform the given activities. Click the given links and
hyperlinks to access the suggested learning resources.)
Printed: Cobre, E. J., Olalia, N., &Tingzon, K. (2019). ICT Tools Today High School Series Computers for Digital Learners
Grade 10 (1st ed., Vol. 1) [Book]. The Phoenix Publishing house Inc.
In this week’s module, we'll learn everything about different types of operators in Python, their syntax and how to
use them with examples
27
Directions: Fill in the K-W-H-L Chart below to assess your prior knowledge and understanding of the topic, Select Case
Structure.
What I Want to Find How I Can Learn
What I Know What I Have Learned
Out More
SHORT EXERCISES/DRILLS:
Direction: Evaluate the Program Line
Analyze this code: x = 15
y=4
sub = 10 - 5# 5
+ Addition 5+2=7
- Subtraction 4-2=2
28
* Multiplication 2*3=6
/ Division 4/2=2
% Modulo 5%2=1
** Power 4 ** 2 = 16
# addition
print ('Sum: ', a + b)
# subtraction
print ('Subtraction: ', a - b)
# multiplication
print ('Multiplication: ', a * b)
# division
print ('Division: ', a / b)
# modulo
print ('Modulo: ', a % b)
# a to the power b
print ('Power: ', a ** b)
Output
Sum: 9
Subtraction: 5
Multiplication: 14
Division: 3.5
Modulo: 1
Power: 49
# assign 5 to x
var x = 5
Here, = is an assignment operator that assigns 5 to x.
Here's a list of different assignment operators available in Python.
29
+= Addition Assignment a += 1 # a = a + 1
-= Subtraction Assignment a -= 3 # a = a - 3
*= Multiplication Assignment a *= 4 # a = a * 4
/= Division Assignment a /= 3 # a = a / 3
%= Remainder Assignment a %= 10 # a = a % 10
# assign 5 to b
b = 5
print(a)
# Output: 15
Here, we have used the += operator to assign the sum of a and b to a.
Similarly, we can use any other assignment operators according to the need.
b = 2
# equal to operator
30
print('a == b =', a == b)
a == b = False
a != b = True
a > b = True
a < b = False
a >= b = True
a <= b = False
Logical AND:
and a and b
True only if both the operands are True
Logical OR:
or a or b
True if at least one of the operands is True
Logical NOT:
not not a
True if the operand is False and vice-versa.
# logical OR
print(TrueorFalse) # True
# logical NOT
print(notTrue) # False
31
Identity operators
In Python, is and is not are used to check if two values are located on the same part of the memory. Two variables that are equal does
not imply that they are identical.
is True if the operands are identical (refer to the same object) x is True
is not True if the operands are not identical (do not refer to the same object) x is not True
32
5. What are the assignment operators?
Prepared: Checked:
Noted:
ANNABELLE G. TACADENA
School Principal
33