Chapter – 3: DATA HANDLING
Very Short answer Type
Questions
Q.1 Identify the data types of
the following values given bellow –
3,
3j, 13.0, „12‟,”14”, 2+0j,19, [1,2,3],(3,4,5)
Ans: 3 – int 3j
– complex 13.0 – float ‗12‘ – string ―14‖
– string
2+0j
– complex 19
– int [1,2,3]
– list (3,4,5)
– tuple
Q.2 What will be the
output of the following
(a)12/4 (b)14//14
(c)14%4 (d) 14.0/4 (e) 14.0//4 (f)14.0%4
Ans: (a) 3.0 (b)
1 (c)
2 (d)
3.5 (e)
3.0 (f)
2.0
Q.3
What will be the output of
the following ?
Ans:
4
4.25
1 4
Q.4
What will be the output of
the following ?
(a) bool(0) (b)
bool(„0‟) (c) bool(int(„0‟))
(d)
bool(str(0.0)) (e) bool(0j) (f)
bool(0.0)
Ans: (a) False (b) True (c) False
(d) True (e)
False (f)
False
Q.5
What will be the output of
the following ?
(a)87//5 (b)(87//5.0) == (87//5) (c) 87//5.0 (d)
17%5.0
Ans: (a) 17 (b)
True (c)
17.0 (d) 2.0
Q.6
int(„a‟) produces error. Why?
Ans: This is because ‗a‘ is an invalid literal
for int() with base 10. Q.7 Write following expressions in Python.
(d)
Ans:
(a) (b*b*h)/3
(b)
d=math.sqrt(pow(x2-x1,2)+pow(y2-y1,2)) (c) x1=((-b)
+ math.sqrt((b*b)-(4*a*c)))/(2*a) x2=((-b) -
math.sqrt((b*b)-(4*a*c)))/(2*a)
(d) pow(a,n) * pow(a,m) = pow(a,m+n)
Short Answer Type
Questions
Q.1
What are data types? What
are Python‟s built-in core data types?
Ans: Every value in Python has a datatype. Since everything is an
object in Python programming,
data types are actually classes
and variables are instance (object) of these classes.
There are various data types in
Python. Some of the important types are listed below.
(i) Numbers (ii)
String (iii) List (iv) Tuple (v)
Dictionary Q.2 Which data types of Python handle Numbers?
Ans: It is cleared by name that Number data types are used to store
numeric value in Python. The Numbers in Python have following core data
types:
(i)
Integers
a.
Integers (signed)
b.
Booleans
(ii)
Floating-Point Numbers
(iii)
Complex Numbers
Q.3
Why is
Boolean considered a subtype of Integers?
Ans: Because Boolean Values False
and True behave like the values 0 and
1, respectively. So Boolean type is a subtype of plain integers.
Q.4
What do you
understand by term „immutable‟?
Ans: Immutable types are those data types that can never change
their value in place. In Python the following types are immutable:
(i)
integers
(ii)
floating-point numbers
(iii)
Booleans
(iv)
Strings
(v)
Tuples
Q.5 What will be
the output of the following code? Why?
(a) 13 or len(13)
(b) len(13) or 13
Ans: (a) 13 (b)
TypeError: object of type 'int' has no len().
Q.6
What are mutable and immutable
types in Python? List both of them.
Ans: Mutable types means those data types whose values can be
changed at the time of execution.
They are as follows:
•
Lists
•
Dictionaries
•
Sets
Immutable types are those data types that
can never change their value in place. In Python the following types are
immutable:
•
integers
•
floating-point numbers
•
Booleans
•
Strings
•
Tuples
Q.7
What are augmented assignment
operators? How are they useful?
Ans: An augmented
assignment is generally used to replace a statement where an operator takes a variable as one
of its arguments and then assigns the result back to the same variable. A
simple example is x += 1 which is expanded to x = x + (1). Similar
constructions are often available for various binary operators. They are
helpful in making the source code small.
Skill Based Questions
Q.1 WAP to calculate
compound simple interest after taking the principle, rate and time.
Ans:
Q.2
WAP to check the given year is leap
year or not.
Ans:
Q.3 WAP to take two numbers and check that the
first number is fully divisible by second number or not.
Ans:
Q.4
What will be the output of the following?
Ans: -2
6561
Q.5
What will be the output of the following?
Ans: 4.0
Q.6 WAP
to take value of x,y,z from the user and calculate the equation Ans:
Q.7 WAP to take the temperatures of all 7 days
of the week and displays the average temperature of that week.
Ans:
0 comments:
Post a Comment
Thanks for leaving a comment. As soon as it's approved, it will appear.