Unit Ii
Unit Ii
https://www.poriyaan.in/
PROGRAMMING https://eee.poriyaan.in/
UNIT – II
DATA, EXPRESSIONS, STATEMENTS
/
in
PART-A
Problem Solving and Python Programming
1. What is meant by interpreter?
n.
An interpreter reads a high-level program and executes it. It takes single
aa
instruction as input and executes one line at a time. Errors are displayed for every
instruction.
riy
Example: Python, java.
o
.p
➢ Iterative Mode: It allows writing codes in python command prompt. The
Chevron >>> is the prompt used by the interpreter to indicate that it is ready to
w
accept input. Here code will produce immediate results. It is useful to test small
codes.
w
➢ Script Mode: It is a text file containing the python statements. In this mode
python program is typed in a file and then using interpreter it will be executed to get
//w
python has.
tp
➢ Number
➢ String
ht
➢ List
➢ Tuple
➢ Dictionary
5. Define a variable and write down the rules for naming variable.
Variable is a name that refers to a value. When a variable is created it will
allocate some memory space to store values in memory.
/
in
expression is evaluated using assignment operator.
n.
Example: Y=X+17
aa
7. Define statement and mention the difference between statement and an
expression.
iy
Instruction that a python interpreter can execute are called statement. A statement is
a unit of code like creating a variable or displaying a value. The important difference is
or
that an expression has a value but a statement does not have a value.
.p
8. Outline the logic to swap the contents of two identifiers without using third
variables.
w
Program:
w
x=10
y=20
//w
x,y=y,x
print(“Value of x=*x)
print(“Value of y=*y)
s:
Output:
Value of x=20
tp
Value of y=10
ht
• Arithmetic operator
• Relational operator
• Assignment operator
• Logical operator
• Bitwise operator
• Membership operator
• Identity operator
10. State about logical operator available in python language with example.
Logical operators are used to check two or more conditions at the same time. It returns
Boolean value.
• And-if all conditions are True it means True otherwise False.
• Or-if any one of the conditions is True it returns True otherwise False.
• Not-if the input is true output will be false and vice-versa.
11. What do you mean by an operand and an operator? Illustrate your answer with
relevant Example.
/
in
Example: a+20*b-32
In this example: a,b, 20 and 32 are operand and +,* and – are operators.
n.
12. What is meant by rule of precedence? Give the order of precedence.
aa
The set of rules that govern the order in which expressions involving multiple
riy
operators and operands are evaluated is known as rule of precedence. “PEMDAS” is
an acronym used to remember the precedence of operators. Parentheses have the
highest precedence followed by exponentiation. Multiplication and division have the
o
next highest precedence followed by addition and subtraction.
Example: [2+5)-12/4*7
Functions are set of related statements that will perform a specific task. It helps to
break the program into small units. It makes program small by eliminating repetitive
codes. Small parts of program can be debugged and tested separately.
17. State the reasons to divide programs into functions.
It makes program small by eliminating repetitive codes provides Re-usability, Small
parts of program can be debugged and tested separately. The length of a program can be
reduced.
18. Define arguments and parameter.
/
Arguments- Values provided in function call are called as Arguments. It is also called
in
as Actual Arguments
n.
Parameters- Values provided in function call are called as Parameters. It is also called
as formal arguments.
aa
Example:
Def Add(x,y): #function Definition
iy
Print(x,y)
a=10
or
b=15
Add(a,b) #function call
.p
Here x and y are formal parameters. a and b are actual parameters.
Example:
Def Display();
s:
Display()
ht
Global variables are the one that are defined and declared outside a function. It can
only be accessed, used and visible anywhere in the program.
Example:
a=10 #Global Variable
def Display();
print(“Value of a=”,a)
Display()
Output: Value of a = 10
21. Comment with an example on the use of local and global variable with the same
identifier name.
https://www.poriyaan.in/ https://eee.poriyaan.in/
A variable defined inside a function is called as local variable. It can only be
accessed, used and visible only within the function.
Example:
a=10 #Global Variable
/
def Display();
in
a=30 #Local Variable
n.
Print(“Value of a inside function=”,a)
Display()
Print(“Value of a outside function=”,a)
aa
Output:
Value of a inside function = 30
riy
Value of a outside function = 10
o
.p
w
w
//w
s:
tp
ht
Problem Solving and Python Programming (GE3151) – Reg 2021
Unit I: Computational Thinking and Problem Solving
Computational Thinking and Problem Solving | Fundamentals of Computing | Identification of Computational Problems |
Algorithms | Building Blocks | Notation | Algorithmic Problem Solving | Simple Strategies for Developing Algorithms |
Illustrative Problems | Anna University Two Marks Questions & Answers | Multiple Choice Questions and Answers
https://www.poriyaan.in/