Engineering Python : UNIT II : Data Types, Expressions, Statements : Anna University Two Marks Questions & Answers
Two Marks Questions with Answers
Q.
1 Enlist some features of python.
Ans. : Following some features of Python:
1.
Python is free and open source programming language. The software can be downloaded
and used freely.
2.
It high level programming language.
3.
It is an object oriented programming language.
4.
This language used interpreter for its interpretation.
Q.
2 What is script mode in python ?
Ans. : The script mode in python is a mode in
which the python commands are stored in a file and the file is saved using the
extension .py
Q.
3 What is the use of type command in python ?
Ans. : The type command is used to determine
the type of the value used. For example type(10) will return 10.
Q.4
Explain the precedence rules used in precedence operation.
Ans. : 1. P : Parentheses have the highest
precedence and can be used to force an
expression
to evaluate in the order you want. Since expressions in parentheses are
evaluated first, 1 * (10-5) is 5
2.
E: Exponentiation has the next highest precedence, so 2**3 is 8.
3.
MDAS : Multiplication and Division have the same precedence, which is
higher than Addition and Subtraction, which also have the same precedence. So
2+3*4 yields 14 rather than 20.
4.
Operators with the same precedence are evaluated from left to right. So in the expression
3 – 2+1 will result 2. As subtraction is performed first and then addition will
be performed.
Q.
5 What is tuple ?
Ans. : Tuple is a sequence of items of any
type. Syntactically tuple is a comma separated list of values.
For
example - The tuple can be created as follows:
>>>
student = ('AAA',96,'Std_X')
Q.
6 What is comment statement ? How do we use comment statement in Python ?
Explain with example.
Ans. : Comments are non executing statements
used for program understanding purpose. In Python we use # symbol to write the
comment. For example
#
This is a comment line
Q.7
How to define a function in Python?
Ans. : The function can be defined using the
def. The syntax of function definition is as follows:
def
function_name(parameters):
statements
Example
def
my_function(a,b):
print("a=")
print(b=
")
Q.
8 Name four types of scalar objects Python has.
Ans. : The commonly used scalar types in
Python are :
AU
Jan. 18
1.
int: Any integer.
2.
float:Floating point number (64 bit precision)
3.
complex: Numbers with an optional imaginary component.
4.
Bool: True, False
Q.
9 What is a Python ?
Ans. : Python is a high-level, interpreted,
interactive and object-oriented scripting language. Python is designed to be
highly readable. It uses English keywords frequently where as other languages
use punctuation, and it has fewer syntactical constructions than other
languages
Q.
10 What are the basic modes in Python ?
Ans. : script and interactive.
Q.
11 What is value ?
Ans. : The value is one of the fundamental
things like a word or a number that a program manipulates. The values we have
seen so far are 5 (the result when added 2 + 3) and "Hello, World !".
We often refer these values as objects and we will use the words value and
object interchangeably.
Q.12
What is a data type or simply type ?
Ans. : Data type or simply type
is a classification of data which tells the compiler or interpreter how
the programmer intends to use the data
Q.
13 Give short note on expression ?
Ans. : An expression is a combination
of values, variables, operators, and calls to functions. Expressions need to be
evaluated.
An
expression is an instruction that combines values and operators and
always evaluates down to a single value.
Q.
14 Outline the logic to swap the contents of two identifiers without using
third variable.
AU
: May-19
Ans. :
def
swap(a,b);
a
= a + b
b
= a - b
a
= a - b
print("a
= ",a)
print("b
= ",b)
a
= 10
b
= 20
print("Before
swapping...")
print("a
= ",a)
print("b
= ",b)
print("After
swapping...")
swap(a,b)
Output
Before
swapping...
a
= 10
b
= 20
After
swapping...
a
= 20
b
= 10 >>>
Q.
15 State the reasons to divide the program into functions. AU : Dec.- 19
Ans. : When a set of instructions that a
programmer want to use repeatedly, then those set of instructions are wrapped
into a function. That means function is written to perform a specific task.
The
reasons to divide the program into functions are as follows –
1)
The functions decompose the complex problems into simple modules.
2)
It allows reusability of the code.
3)
It allows some kind of information hiding.
4)
Checking the bugs from the program becomes easy.
Problem Solving and Python Programming: UNIT II: Data Types, Expressions, Statements : Tag: Engineering Python : Data Types, Expressions, Statements | Problem Solving and Python Programming - Anna University Two Marks Questions & Answers
Problem Solving and Python Programming
GE3151 1st Semester | 2021 Regulation | 1st Semester Common to all Dept 2021 Regulation