0% found this document useful (0 votes)
3 views28 pages

Python Module II

Module II introduces Python variables, expressions, and statements, covering topics such as control statements, Boolean expressions, and string operations. It explains how to run Python code using the shell or as standalone scripts, along with the role of the Python interpreter in executing code. Additionally, it discusses the character set, constants, variables, data types, and various operators in Python, including arithmetic, logical, and membership operators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views28 pages

Python Module II

Module II introduces Python variables, expressions, and statements, covering topics such as control statements, Boolean expressions, and string operations. It explains how to run Python code using the shell or as standalone scripts, along with the role of the Python interpreter in executing code. Additionally, it discusses the character set, constants, variables, data types, and various operators in Python, including arithmetic, logical, and membership operators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

MODULE II: Variable Expression and Statements

Introduction to Python-variables,expressions and statements, evaluation of expressions, precedence, string


operations Control statements, Boolean expressions and logical operators, conditional and alternative
executions.

Introduction to Python

Python is a high-level, interpreted language. Its features are:


• Python is interpreted: Python is processed at runtime by the interpreter.You need not compile your
program before executing it.
• Python has simple, conventional syntax: Python statements are very close to those of pseudocodes, and
Python expressions use the conventional notation found in algebra.
• Python is highly interactive: Expressions and statements can be entered at an interpreter’s terminal to
allow the programmer to try out the code and receive immediate output.
• Python is object-oriented: Python supports Object-Oriented Programming (OOP) principles. OOP closely
models real-world objects and their interactions, leading to more natural and understandable program
structures.
• Python scales well: Python is the most apt language in which a novice programmer can start coding. At
the same time, it is so powerful to cater to the research community’s needs

How to run your Python code?


There are two ways you can run your Python code:
1. using the Python shell
2. running as a standalone script

Using Python shell


The Python shell is an interactive terminal-based environment wherein you can directly communicate with
the Python interpreter. First, you open a terminal and type python3. Now the shell turns up with a welcome
message as shown below.

user@Ubuntu2204LTS:~$ python3
Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

The symbol >>> is called the shell prompt. This symbol prompts you for Python statements. When you
enter a statement in the shell, the Python interpreter processes it and displays the result, if any, then
followed by a new prompt as shown below:
>>> "Welcome to the world of Python programming"
'Welcome to the world of Python programming'
>>>
The shell-based execution of Python code will become cumbersome if you want to do some complex
processing. You may have to type in a lot of Python statements and you can give only one command at a
time to the interpreter. Undoubtedly, this is frustrating for most of us. The workaround is to run your code
as a standalone script.

Running as a standalone script

Here are the steps:


1. Combine all the statements that you wish to execute into a Python program.program is known as script
and should be saved with “py” extension,for example sample.py.
2. You may use some text editor to create your script. gedit, vim are some of the editors that you can
probably use.
3. Then open a terminal in the directory where the script is stored. To run your script (assuming the name is
sample.py), just give
python3 sample.py
Now the script will be executed and you get the desired output.

The Python interpreter

As shown in Figure 4.1, the interpreter performs a sequence of steps to execute your script:
1. The interpreter first reads a Python expression or a statement and verifies that it is valid with regard to
the rules, or syntax, of the language. Any invalid statement is called a syntax error. When the interpreter
encounters such an error, it halts with an error message.
2. If the expression is well formed, the interpreter then translates it to an executable form called byte code.
The Syntax checker and Translator component of the interpreter is responsible for verifying the syntax of
the statements and translating valid statements to byte code.
3. Then, the byte code is sent to another interpreter component called the Python Virtual Machine (PVM)
for execution. If any error occurs during execution, the process is halted with a runtime error message.
Otherwise, the execution runs to completion and the output is produced.

Starting with Python


You started with learning the alphabet and then forming words out of them. Later you combined words to
create meaningful sentences, then progressed to form paragraphs out of sentences.Finally, an article or an
essay consists of one or more paragraphs.

You follow the same procedure to learn Python. As Figure 4.3 illustrates, you start with the basic building
bricks: alphabets, numbers, and special symbols. Then, you combine them to build the foundation:
constants, variables, and keywords. Over the foundation, you create rooms viz. expressions or
instructions.A group of rooms (instructions) constitute a building (Python function). The Python city
(program) is carved out of multiple buildings (functions).

Character set
The set of characters supported by a programming language is called character set. A character can be an
alphabet, a digit, or a special symbol. Python supports the following characters:
• upper case alphabets (A–Z)
• lower case alphabets (a–z)
• digits (0–9)
• special symbols like @,#,%,$ etc.
Python maps each valid character to an integer value called ASCII value.
(ASCII is the abbreviation of American Standard Code for Information Interchange.)
Constants
When properly combined, the characters in the character set form constants,variables, and keywords. A
‘constant’ is an entity whose value doesn’t change.
3, 100, etc. are all constants.
Variables, and keywords
Variable is an identifier whose value can change. For example, variable age can have different values for
different people. Variable names should be unique in a program. Value of a variable can be a string,number
or any combination of alphanumeric (alphabets and numbers for example ‘b10’) characters. In Python, we
can use an assignment statement to create new variables and assign specific values to them.
gender = 'M'
message = "Keep Smiling"
price = 987.9
Variables must always be assigned values before they are used in the program, otherwise it will lead to an
error. Wherever a variable name occurs in the program, the interpreter replaces it with the value of that
particular variable.
Program : Write a Python program to find the sum of two numbers.
num1 = 10
num2 = 20
result = num1 + num2
print(result)
OUTPUT
30
Program : Write a Python program to find the area of a rectangle given that its length is 10 units and
breadth is 20 units.
length = 10
breadth = 20
area = length * breadth
print(area)
Output:
200

You should choose meaningful names for your variables. The names can include both letters and digits;
however, there are restrictions:
1. Variable names must start with a letter or the underscore ‘_’ and can be followed by any number of
letters, digits, or underscores.
2. Variable names are case sensitive; thus, the variable COUNT is a different name from the variable count.
3. Variable names cannot be a keyword. Keywords(also called reserved words) are special words, reserved
for other purposes; thus, they cannot be used as variable names. Python has thirty-three keywords .All the
keywords except True, False, and None are in lowercase, and they must be written as is.
Each keyword has a specific meaning to the Python interpreter. As Python is case sensitive, keywords must
be written exactly as given in Table
Data types

Any data item stored in memory has an associated data type. For example,your roll number is stored as a
number whereas your name is stored as a string.
The data type of an item defines the operations that can be performed on it,and how the values are stored in
memory. Python supports the following data
types:
• Number
• String
• List
• Tuple
• Set
• Dictionary
Here, Only the first two are discussed. The remaining data types will be explored in later chapters.
Numbers
The number or numeric data type is used to store numeric values. There are three distinct numeric types:
Type Description Examples
int integers 700,198005
float numbers with decimal point 3.14,6.023
complex complex numbers 3+4j, 10j
The integers include numbers that do not have decimal points. The int data type supports integers ranging
from −231 to 231 − 1.
Python uses float type to represent real numbers (with decimal points).
complex numbers are written in the form x+yj, where x is the real part and y is the imaginary part.
int type has a subtype boolean. Any variable of type bool can take one of the two possible boolean values,
True and False (internally represented as 1 and 0,respectively).
Variables of simple data types like integer, float, boolean etc. hold a single value. But such variables are not
useful to hold multiple data values, for example, names of the months in a year, names of students in a
class, names and numbers in a phone book or the list of artifacts in a museum. For this, Python provides
sequence data types like Strings, Lists, Tuples, and mapping data type Dictionaries.
String
String is a group of characters. These characters may be alphabets, digits or special characters including
spaces. String values are enclosed either in single quotation marks (for example ‘Hello’) or in double
quotation marks (for example “Hello”). The quotes are not a part of the string, they are used to mark the
beginning and end of the string for the interpreter. For example,
>>> str1 = 'Hello Friend'
>>> str2 = "452"
We cannot perform numerical operations on strings, even when the string contains a numeric value. For
example str2 is a numeric string.

Statements
A statement is an instruction that the Python interpreter can execute. A statement can be an expression
statement or a control statement. An expression statement contains an arithmetic expression that the
interpreter evaluates. A control statement is used to represent advanced features of a language like
decision-making and looping.
Expressions
An arithmetic expression comprises operands and operators. Operands represent data items on which
various operations are performed. The operations are denoted by operators. The operands can be constants
or variables. When a variable name appears in the place of an operand, it is replaced with its value before
the operation is performed. The operands acted upon by arithmetic operators, must represent numeric
values. Thus, the operands can be integer quantities, floating-point quantities, or even characters.
Some examples of valid expressions are given below.
(i) num – 20.4
(iii) 23/3 -5 * 7(14 -2)
(ii) 3.0 + 3.14
(iv) "Global"+"Citizen"

Python language supports the following types of operators.


• Arithmetic Operators
• Comparison (Relational) Operators
• Assignment Operators
• Logical Operators
• Bitwise Operators
• Membership Operators
• Identity Operators

Arithmetic Operators
Relational Operators/Comparison operators
The result of a comparison is either True or False. == and != are also known as equality operators.
Assignment Operators
Assignment operator assigns or changes the value of the variable on its left.

Logical Operators
There are three Boolean/logical operators (Table 3.6) supported by Python. These operators (and, or, not)
are to be written in lower case only. The logical operator evaluates to either True or False based on the
logical operands on its either side.
a or b =
a and b=
Bitwise Operators
Python bitwise operators are used to perform bitwise calculations on integers. The integers are first
converted into binary and then operations are performed on each bit or corresponding pair of bits,hence the
name bitwise operators. The result is then returned in decimal format.
Example1
Let’s take a number 14.
Binary representation of 14 is 00001110 (for the sake of clarity let’s write it using 8 bit)
14 = (00001110) 2
Then 14 << 1 will shift the binary sequence 1 position to the left side.
Like,

Logical bitwise operators:


There are three logical bitwise operators: bitwise and (&), bitwise exclusive
or (∧), and bitwise or ( | ). Each of these operators require two integer-type
operands. The operations are performed on each pair of corresponding bits of
the operands based on the following rules:
• A bitwise and expression will return 1 if both the operand bits are 1.
Otherwise, it will return 0.
• A bitwise or expression will return 1 if at least one of the operand bits
is 1. Otherwise, it will return 0.
• A bitwise exclusive or expression will return 1 if the bits are not alike
(one bit is 0 and the other is 1). Otherwise, it will return 0.

Membership Operators
These operators test for the membership of a data item in a sequence, such as a string. Two membership
operators are used in Python.
• in – Evaluates to True if it finds the item in the specified sequence and False otherwise.
• not in – Evaluates to True if it does not find the item in the specified sequence and False otherwise.
Identity Operators
is and is not are the identity operators in Python. They are used to check if two values (or variables) are
located in the same part of the memory. x is y evaluates to true if and only if x and y are the same object. x
is not y yields the inverse truth value.
EXPRESSIONS
An expression is defined as a combination of constants,variables and operators. An expression always
evaluates to a value. A value or a standalone variable is also considered as an expression but a standalone
operator is not an expression. Some examples of valid expressions are given below.
(i) num – 20.4 (iii) 23/3 -5 * 7(14 -2)
(ii) 3.0 + 3.14 (iv) "Global"+"Citizen"
Precedence of Operators
When an expression contains more than one operator, their precedence (order or hierarchy)
determines which operator should be applied first.
The order in which operators in an arithmetic expression are applied to their respective operands is called
the precedence of operators. It is also known by other names, such as priority or hierarchy.Operators with a
higher precedence are applied before operators having a lower precedence.
Higher precedence operator is evaluated before the lower precedence operator.
For example, the multiplication operator has precedence over the addition operator. This means that if an
expression has both + and ∗, then addition will be performed only after multiplication.

Note:
a) Parenthesis can be used to override the precedence of operators. The expression within () is evaluated
first.
b) For operators with equal precedence, the expression is evaluated from left to right.
String operations
String is a sequence which is made up of one or more UNICODE characters. Here the character can be a
letter, digit, whitespace or any other symbol. A string can be created by enclosing one or more characters in
single,double quotes
>>>str1 = 'Hello World!'
>>>str2 = "Hello World!"
Values stored in str3 and str4 can be extended to multiple lines using triple codes as can be seen in the
following example:
>>>str3 = """Hello World!
welcome to the world of Python"""
>>>str4 = '''Hello World!
welcome to the world of Python'''
Accessing Characters in a String
Each individual character in a string can be accessed using a technique called indexing. The index specifies
the character to be accessed in the string and is written in square brackets ([ ]). The index of the first
character (from left) in the string is 0 and the last character is n-1 where n is the length of the string. If we
give an index value out of this range then we get an IndexError. The index must be an integer (positive,
zero or negative).

.
>>> str1 = 'Hello World!'
>>>str1[0]
'H'
>>> str1[6]
'W'
>>>str1[11]
'!'
#gives error as index is out of range
>>> str1[15]
IndexError: string index out of range
The index can also be an expression including variables and operators but the expression must
evaluate to an integer.
>>>str1[2+4]
'W'
#gives error as index must be an integer
>>>str1[1.5]
TypeError: string indices must be integers
Python allows an index value to be negative also.Negative indices are used when we want to access the
characters of the string from right to left. Starting from right hand side, the first character has the index as
-1 and the last character has the index –n where n is the length of the string.
Table 8.1 shows the indexing of characters in the string ‘Hello World!’ in both the cases,i.e., positive and
negative indices.
>>>str1[-1]
'!'
>>>Str1[-12]
'H'

An inbuilt function len() in Python returns the length of the string that is passed as parameter. For
example,the length of string str1 = 'Hello World!' is 12.

>>>len(str1)
12
>>> n = len(str1)
>>> print(n)
12

String Operations
As we know that string is a sequence of characters.Python allows certain operations on string data
type,such as concatenation, repetition, membership and slicing. These operations are explained in the
following subsections with suitable examples

Concatenation
To concatenate means to join. Python allows us to join two strings using concatenation operator plus which
is denoted by symbol +.
>>>str1 = 'Hello'
>>>str2 = 'World!'
>>>str1 + str2

'HelloWorld!'
Repetition
Python allows us to repeat the given string using repetition operator which is denoted by symbol *.
>>>str1 = 'Hello'
>>>str1 * 2
'HelloHello'
>>>str1 * 5
'HelloHelloHelloHelloHello'
Membership
Python has two membership operators 'in' and 'not in'. The 'in' operator takes two strings and returns True if
the first string appears as a substring in the second string, otherwise it returns False.
>>> str1 = 'Hello World!'
>>> 'W' in str1
True
>>> 'Wor' in str1
True
>>> 'My' in str1
False
The 'not in' operator also takes two strings and returns True if the first string does not appear as a
substring in the second string, otherwise returns False.
>>> str1 = 'Hello World!'
>>> 'My' not in str1
True
>>> 'Hello' not in str1
False

Slicing
In Python, to access some part of a string or substring,we use a method called slicing. This can be done by
specifying an index range. Given a string str1, the slice operation str1[n:m] returns the part of the string
str1 starting from index n (inclusive) and ending at m (exclusive). In other words, we can say that str1[n:m]
returns all the characters starting from str1[n] till str1[m-1]. The numbers of characters in the substring will
always be equal to difference of two indices m and n, i.e., (m-n).
>>> str1 = 'Hello World!'
>>> str1[1:5] (gives substring starting from index 1 to 4 )
'ello'

>>> str1[7:10] (gives substring starting from 7 to 9)


'orl'

>>> str1[3:20] (index that is too big is truncated down to the end of the string)
'lo World!'

>>> str1[7:2] (first index > second index results in an empty ' ' string)
If the first index is not mentioned, the slice starts from 0 index.

>>> str1[:5] (gives substring from index 0 to 4)


'Hello'
If the second index is not mentioned, the slicing is done till the length of the string.

>>> str1[6:] (gives substring from index 6 to end)


'World!'
The slice operation can also take a third index that specifies the ‘step size’. For example, str1[n:m:k],means
every kth character has to be extracted from the string str1 starting from n and ending at m-1. By default,
the step size is one.
>>> str1[0:10:2]
'HloWr'
>>> str1[0:10:3]
'HlWl'
Negative indexes can also be used for slicing.

>>> str1[-6:-1] (characters at index -6,-5,-4,-3 and -2 are sliced)


'World'
If we ignore both the indexes and give step size as -1
>>> str1[::-1] (str1 string is obtained in the reverse order )
'!dlroW olleH'
Traversing a String
We can access each character of a string or traverse a string using for loop and while loop.
(A) String Traversal Using for Loop:
>>> str1 = 'Hello World!'
>>> for ch in str1:
print(ch,end = '')
Hello World!
In the above code, the loop starts from the first character of the string str1 and automatically ends
when the last character is accessed.
(B) String Traversal Using while Loop:
>>> str1 = 'Hello World!'
>>> index = 0
#len(): a function to get length of string
>>> while index < len(str1):
print(str1[index],end = '')
index += 1
Hello World!
Here while loop runs till the condition index < len(str) is True, where index varies from 0 to
len(str1) -1.
Conditional and alternative executions

The order of execution of the statements in a program is known as flow of control. The flow of
control can be implemented using control structures. Python supports two types of control
structures—selection and repetition.

Selection

Now, suppose we want to display the positive difference of the two numbers
num1 and num2.
Subtract the smaller number from the bigger number so that we always get a
positive difference. This selection is based upon the values that are input for the
two numbers num1 and num2.

The syntax of if statement is:


if condition:
statement(s)

Example 6.1
age = int(input("Enter your age "))
if age >= 18:
print("Eligible to vote")

In the above example, if the age entered by the user is greater than 18, then print that the user is
eligible to vote. If the condition is true, then the indented statement(s) are executed. The
indentation implies that its execution is dependent on the condition. There is no limit on the
number of statements that can appear as a block under the if statement.

A variant of if statement called if..else statement allows us to write two alternative paths and the
control condition determines which path gets executed. The syntax for if..else statement is as
follows.

if condition:
statement(s)
else:
statement(s)

Let us now modify the example on voting with the condition that if the age entered by the user is
greater than 18, then to display that the user is eligible to vote. Otherwise display that the user is
not eligible to vote.

age = int(input("Enter your age: "))


if age >= 18:
print("Eligible to vote")
else:
print("Not eligible to vote")

Many a times there are situations that require multiple conditions to be checked and it may lead to
many alternatives. In such cases we can chain the conditions using if..elif (elif means else..if).
The syntax for a selection structure using elif is as shown below.
if condition:
statement(s)
elif condition:
statement(s)
elif condition:
statement(s)
else:
statement(s)

Example: Check whether a number is positive,negative, or zero.

number = int(input("Enter a number: ")


if number > 0:
print("Number is positive")
elif number < 0:
print("Number is negative")
else:
print("Number is zero")

Example : Display the appropriate message as per the colour of signal at the road crossing.

signal = input("Enter the colour: ")


if signal == "red" or signal == "RED":
print("STOP")
elif signal == "orange" or signal =="ORANGE":
print("Be Slow")
elif signal == "green" or signal == "GREEN":
print("Go!")

Number of elif is dependent on the number of conditions to be checked. If the first condition is
false,then the next condition is checked, and so on. If one of the conditions is true, then the
corresponding indented block executes, and the if statement terminates.
Indentation
In most programming languages, the statements within a block are put inside curly brackets.
However, Python uses indentation for block as well as for nested block structures. Leading
whitespace (spaces and tabs) at the beginning of a statement is called indentation.
In Python, the same level of indentation associates statements into a single block of code. The
interpreter checks indentation levels very strictly and throws up syntax errors if indentation is not
correct. It is a common practice to use a single tab for each level of indentation.

Repetition

Often, we repeat a tasks, for example, payment of electricity bill, which is done every month.
Figure shows the life cycle of butterfly that involves four stages, i.e., a butterfly lays eggs, turns
into a caterpillar, becomes a pupa, and finally matures as a butterfly. The cycle starts again with
laying of eggs by the butterfly.This kind of repetition is also called iteration.
Repetition of a set of statements in a program is made possible using looping constructs.

Write a program to print the first five natural numbers.


print(1)
print(2)
print(3)
print(4)
print(5)
Output:
1
2
3
4
5
To print the first 100,000 natural numbers ,writing a program having a loop or repetition is a better
solution.
The program logic is given below:
1. Take a variable, say count, and set its value to 1.
2. Print the value of count.
3. Increment the variable (count += 1).
4. Repeat steps 2 and 3 as long as count has a value
less than or equal to 100,000 (count <= 100,000).

Looping constructs provide the facility to execute a set of statements in a program repetitively,
based on a condition. The statements in a loop are executed again and again as long as particular
logical condition remains true. This condition is checked based on the value of a variable called the
loop’s control variable. When the condition becomes false, the loop terminates.

There are two looping constructs in Python - for and while.

The ‘for’ Loop

The for statement is used to iterate over a range of values or a sequence. The for loop is executed
for each of the items in the range. These values can be either numeric, or they can be elements of a
data type like a string, list, or tuple.With every iteration of the loop, the control variable checks
whether each of the values in the range have been traversed or not. When all the items in the range
are exhausted, the statements within loop are not executed; the control is then transferred to the
statement immediately following the for loop. While using for loop, it is known in advance the
number of times the loop will execute.

Syntax of the for Loop


for <control-variable> in <sequence/items in range>:
<statements inside body of the loop>

Ex:Print the characters in word PYTHON using for loop.

for letter in 'PYTHON':


print(letter)

Output:
P
Y
T
H
O
N

Ex:Program to print the numbers in a range using for loop.

n=10
for i in range(n):
print(i)

OUTPUT
0
1
2
3
4
5
6
7
8
9

The Range() Function


The range() is a built-in function in Python. Syntax of range() function is:

range(start, stop, step)

It is used to create a list containing a sequence of integers from the given start value upto stop
value (excluding stop value), with a difference of the given step value.

The start and step parameters are optional. If start value is not specified, by default the list starts
from 0. If step is also not specified, by default the value increases by 1 in each iteration. All
parameters of range() function must be integers. The step parameter can be a positive or a negative
integer excluding zero.

The ‘while’ Loop


The while statement executes a block of code repeatedly as long as the control condition of the
loop is true. The control condition of the while loop is executed before any statement inside the
loop is executed. After each iteration, the control condition is tested again and the loop continues
as long as the condition remains true. When this condition becomes false, the statements in the
body of loop are not executed and the control is transferred to the statement immediately following
the body of the while loop. If the condition of the while loop is initially false, the body is not
executed even once.
The statements within the body of the while loop must ensure that the condition eventually
becomes false; otherwise the loop will become an infinite loop, leading to a logical error in the
program. The flowchart of while loop is shown in Figure
Syntax of while Loop

while test_condition:
body of while

Eg:Print first 5 natural numbers using while loop


count = 1
while count <= 5:
print(count)
count += 1
Output:
1
2
3
4
5

Ex:Program to find the factors of a whole number using while loop

num = int(input("Enter a number to find its factor: "))


print (1, end=' ') #1 is a factor of every number
factor = 2
while factor <= num/2 :
if num % factor == 0:
print(factor, end=' ')
factor += 1
print (num, end=' ') #every number is a factor of itself

Output:
Enter a number to find its factors : 6
1236

Break and Continue Statement


Looping constructs allow programmers to repeat tasks efficiently. In certain situations, when some
particular condition occurs, we may want to exit from a loop (come out of the loop forever) o r
skip some statements of the loop before continuing further in the loop. These requirements can be
achieved by using break and continue statements, respectively. Python provides these statements as
a tool to give more flexibility to the programmer to control the flow of execution of a program.
Break Statement
The break statement alters the normal flow of execution as it terminates the current loop and
resumes execution of the statement following that loop.
Program to demonstrate the use of break statement in loop-When value of num becomes 8, the
break statement is executed and the for loop terminates.

num = 0
for num in range(10):
num = num + 1
if num == 8:
Break
print(num)
print('Encountered break!! Out of loop')

Output
1
2
3
4
5
6
7
Encountered break!! Out of loop
Continue Statement
When a continue statement is encountered, the control skips the execution of remaining statements
inside the body of the loop for the current iteration and jumps to the beginning of the loop for the
next iteration. If the loop’s condition is still true, the loop is entered again, else the control is
transferred to the statement immediately following the loop.Figure 6.7 shows the flowchart of
continue statement.
Ex:Prints values from 0 to 6 except 3
num = 0
for num in range(6):
num = num + 1
if num == 3:
Continue
print(num)
print('End of loop')

Output
1
2
4
5
6
End of loop

(Prepared by Hrudya K P,AP/CSE,Sahrdaya College of Engineering and


Technology,Kodakara)

You might also like