0% found this document useful (0 votes)
57 views22 pages

CBSE Class11 Computer Chapter 8 CS11 Data Handling Part1

Uploaded by

departha04
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)
57 views22 pages

CBSE Class11 Computer Chapter 8 CS11 Data Handling Part1

Uploaded by

departha04
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/ 22

Chapter 8

Data Handling
Class 11 - Computer Science with Python Sumita
Arora
Multiple Choice Questions

Question 1

Which of the following are valid Python data types ?

1. Numeric
2. None ✓
3. Mappings
4. list ✓
5. Sequence
6. set ✓
7. tuple ✓
8. dictionary ✓

Question 2

Which of the following are datatypes considered as Numbers in Python.

1. Integer ✓
2. Boolean ✓
3. complex ✓
4. floating point ✓
5. list
6. None

Question 3

Consider the following sequence of statements:


a = 35
m=a
Following the execution of these statements, Python has created how many objects and how
many references ?

1. Two integer objects, two references


2. One integer object, two references ✓
3. One integer object, one reference
4. Two integer objects, one reference

Question 4

Which Python built-in function returns the unique number assigned to an object?

1. identity( )
2. id( ) ✓
3. refnum( )
4. ref( )

Question 5

The operator used to check if both the operands reference the same object memory, is the ..........
operator.

1. in
2. is ✓
3. id
4. ==

Question 6

For two objects x and y, the expression x is y will yield True, if and only if

1. id(x) == id(y) ✓
2. len(x) == len(y)
3. x == y
4. all of these

Question 7

Which of the following is not an immutable type in Python ?

1. String
2. Tuples
3. Set ✓
4. dictionary ✓

Question 8

Python operator always yields the result of .......... datatype.

1. integer
2. floating point ✓
3. complex
4. all of these

Question 9

What is the value of the expression 100 / 25 ?

1. 4
2. 4.0 ✓
3. 2.5
4. none of these

Question 10

What is the value of the expression 100 // 25 ?

1. 4✓
2. 4.0
3. 2.5
4. none of these

Question 11

In Python, a variable must be declared before it is assigned a value.

1. True
2. False ✓
3. Only in Functions
4. Only in modules

Question 12
In Python, a variable is assigned a value of one type, and then later assigned a value of a
different type. This will yield .......... .

1. Warning
2. Error
3. None
4. No Error ✓

Question 13

In Python, a variable may be assigned a value of one type, and then later assigned a value of a
different type. This concept is known as .......... .

1. mutability
2. static typing
3. dynamic typing ✓
4. immutability

Question 14

Is it safe to directly use the == operator to determine whether objects of type float are equal ?

1. Yes
2. No ✓
3. Yes, if the values are < 100
4. Yes, if the values are > 100

Question 15

What will the following code produce ?

a = 8.6
b = 2
print ( a//b )

1. 4.3
2. 4.0 ✓
3. 4
4. compilation error

Question 16

In the Python statement x = a + 5 - b : a and b are .......... .


1. Operands ✓
2. Expression
3. operators
4. Equation

Question 17

In the Python statement x =a + 5 - b : a + 5 - b is .......... .

1. Operands
2. Expression ✓
3. operators
4. Equation

Question 18

What will be the value of y after following code fragment is executed ?

x = 10.0
y = (x < 100.0) and x >= 10

1. 110
2. True ✓
3. False
4. Error.

Question 19

Which of the following literals has True truth-value ?

1. 0.000001 ✓
2. 'None' ✓
3. 0
4. []
5. False
6. True ✓
7. 1 ✓
8. 33 ✓
9. None
10. 0.0
Question 20

What will the following code result as ?

import math
x = 100
print ( x > 0 and math.sqrt( x ) )

1. True
2. 1
3. 10
4. 10.0 ✓

Question 21

Which of the following operators has the lowest precedence ?

1. not
2. %
3. and ✓
4. +
5. **

Question 22

What is the value of the expression 10 + 3 ** 3 * 2?

1. 28
2. 739
3. 829
4. 64 ✓

Question 23

To increase the value of x five times using an augmented assignment operator, the correct
expression will be

1. x += 5
2. x *= 5 ✓
3. x = x ** 5
4. none of these
Question 24

What will be the result of the expression 10 or 0 ?

1. 0
2. 1
3. 10 ✓
4. 1.0

Question 25

What will be the result of the expression 5 or 10 ?

1. 5✓
2. 1
3. 10
4. 0

Question 26

What will be the result of the expression 5 and 10?

1. 5
2. 1
3. 10 ✓
4. 0

Question 27

What will be the result of the expression 15 and 10?

1. 5
2. 1
3. 10 ✓
4. 0

Question 28

What will be the result of the expression 10 or 0 ?

1. 0
2. 1
3. 10 ✓
4. 1.0

Question 29

What will be the result of the expression 'a' or " (" is an empty string) ?

1. 'a' ✓
2. "
3. 1
4. 0

Question 30

What will be the result of the expression 'a' and " (" is an empty string) ?

1. 'a'
2. "✓
3. 1
4. 0

Question 31

What will be the result of the expression 'x' and 'a' ?

1. 'a' ✓
2. "
3. 'x'
4. 1

Question 32

What will be the result of the expression 'a' and 'x' ?

1. 'a'
2. ''
3. 'x' ✓
4. 1

Question 33

What will be the result of the expression 'a' and 'None' ?


1. 'a'
2. ''
3. 'None' ✓
4. 1

Question 34

What will be the result of the expression 'None' and 'a' ?

1. 'a' ✓
2. ''
3. 'None'
4. 1

Question 35

What will be the result of the expression 'false' and False ?

1. false
2. False ✓
3. 'false'
4. 'False'

Question 36

What will be the result of the expression 'false' or False ?

1. false
2. False
3. 'false' ✓
4. 'False'

Fill in the Blanks

Question 1

Boolean data type is internally treated as integer data type.

Question 2

Two forms of floating-point numbers are: fractional form and exponent notation.
Question 3

Python's floating point numbers have precision of 15 digits.

Question 4

Three mutable types of Python are lists, dictionaries and sets.

Question 5

The floor division of two integers yields a result of integer type.

Question 6

The division of two integers yields a result of floating-point type.

Question 7

The set sequence type cannot store duplicate values.

Question 8

The tuple datatype is like lists but is not mutable.

Question 9

The id of an object gives the memory location of the object.

Question 10

To check if two objects reference the same memory address, is operator is used.

Question 11

To use function fabs( ), math module should be imported.

Question 12

To generate a random floating number in the range 0 to 100, random() or


random.random() function is used.

Question 13

To generate a random integer in a range, randint() or random.randint() function is used.


Question 14

To generate a random number in a sequence of values where two values have a difference a step
value, randrange() or random.randrange() function is used.

Question 15

To use mean() function, statistics module is to be imported.

True/False Questions

Question 1

List is an immutable data type.


False

Question 2

Set is a mutable data type.


True

Question 3

A set can contain duplicate values in it.


False

Question 4

A Boolean value is internally treated as an integer value.


True

Question 5

'' (an empty string) has truth value as False.


True

Question 6

' ' (a space) has truth value as False.


False

Question 7
Value false is a legal literal value in Python.
False

Question 8

Value False is a legal literal value in Python.


True

Question 9

Value 'False' is a legal literal value in Python.


True

Question 10

Value 'false' is a legal literal value in Python.


True

Question 11

None and 'None' are the same.


False

Question 12

None has the truth value as False.


True

Question 13

'None' has the truth value as False.


False

Question 14

The result of bool(0) is False.


True

Question 15

The result of bool('None') is False.


False

Question 16
Dividing two integers results in an integer.
False

Question 17

Floor division of two integers results in an integer.


True

Question 18

Two floating point numbers should not be compared for equality using ==
True

Question 19

In implicit conversion, all operands' data types are converted to the datatype of the largest
operand.
True

Question 20

Explicit type conversion involves the use of a function to convert datatype of a value.
True
Type A: Short Answer Questions/Conceptual Questions

Question 1

What are data types in Python? How are they important?

Answer

Data types are used to identify the type of data a memory location can hold and the associated
operations of handling it. The data that we deal with in our programs can be of many types like
character, integer, real number, string, boolean, etc. hence programming languages including
Python provide ways and facilities to handle all these different types of data through data types.
The data types define the capabilities to handle a specific type of data such as memory space it
allocates to hold a certain type of data and the range of values supported for a given data type,
etc.

Question 2

How many integer types are supported by Python? Name them.

Answer

Two integer types are supported by Python. They are:

1. Integers (signed)
2. Booleans

Question 3

How are these numbers different from one another (with respect to Python)? 33, 33.0, 33j, 33 + j

Answer

The number 33 is an integer whereas 33.0 is a floating-point number. 33j represent the imaginary
part of a complex number. 33 + j is a complex number.

Question 4

The complex numbers have two parts : real and imaginary. In which data type are real and
imaginary parts represented ?
Answer

In Python, the real and imaginary parts of a complex number are represented as floating-point
numbers.

Question 5

How many string types does Python support? How are they different from one another?

Answer

Python supports two types of strings — Single-line strings and Multi-line strings. Single line
strings are enclosed in single or double quotes and terminate in one line. Multi-line strings store
multiple lines of text and are enclosed in triple quotes.

Question 6

What will following code print?

str1 = '''Hell
o'''
str2 = '''Hell\
o'''
print(len(str1) > len(str2))

Answer

This code will print:

True
len(str1) is 6 due to the EOL character. len(str2) is 5 as backslash (\) character is not counted in
the length of string. As len(str1) is greater than len(str2) so the output is True.

Question 7

What are Immutable and Mutable types in Python? List immutable and mutable types of Python.

Answer

Mutable types are those whose values can be changed in place whereas Immutable types are
those that can never change their value in place.

Mutable types in Python are:

1. Lists
2. Dictionaries
3. Sets
Immutable types in Python are:

1. Integers
2. Floating-Point numbers
3. Booleans
4. Strings
5. Tuples

Question 8

What are three internal key-attributes of a value-variable in Python ? Explain with example.

Answer

The three internal key-attributes of a value-variable in Python are:

1. Type
2. Value
3. Id

For example, consider this:

a=4

The type of a is int which can be found with the built-in function type() like this:
type(a).

Value can be found using the built-in function print() like this:
print(a)

It will give the output as 4 which is value contained in variable a.

Id is the memory location of the object which can be determined using built-in function id() like
this:
id(a)

Question 9

Is it true that if two objects return True for is operator, they will also return True for == operator?

Answer

Yes, if is operator returns true, it implicitly means that the equality operator will also return True.
is operator returning true implies that both the variables point to the same object and hence ==
operator must return True.
Question 10

Are these values equal? Why/why not?

1. 20 and 20.0
2. 20 and int(20)
3. str(20) and str(20.0)
4. 'a' and "a"

Answer

1. The type of 20 is int whereas the type of 20.0 is float so they are two different objects.
Both have the same value of 20. So, as values are same equality (==) operator return True
but as objects are different is operator returns False.
2. The value and type of both 20 and int(20) are the same and both point to the same object
so both equality (==) and is operator returns True.
3. For str(20) and str(20.0), both equality (==) and is operator returns False as their values
are different and they point to two different objects.
4. For 'a' and "a", both equality (==) and is operator returns True as their values are same
and they point to the same object.

Question 11

What is an atom in Python? What is an expression?

Answer

In Python, an atom is something that has a value. Identifiers, literals, strings, lists, tuples, sets,
dictionaries, etc. are all atoms. An expression in Python, is any valid combination of operators
and atoms. It is composed of one or more operations.

Question 12

What is the difference between implicit type conversion and explicit type conversion?

Answer

Implicit Type Conversion Explicit Type Conversion

An implicit type conversion is automatically performed An explicit type conversion is user-defined


by the compiler when differing data types are intermixed conversion that forces an expression to be of
in an expression. specific type.

An implicit type conversion is performed without An explicit type conversion is specified


Implicit Type Conversion Explicit Type Conversion

programmer's intervention. explicitly by the programmer.

Example: Example:
a, b = 5, 25.5 a, b = 5, 25.5
c=a+b c = int(a + b)

Question 13

Two objects (say a and b) when compared using == ,return True. But Python gives False when
compared using is operator. Why? (i.e., a == b is True but why is a is b False?)

Answer

As equality (==) operator returns True, it means that a and b have the same value but as is
operator returns False, it means that variables a and b point to different objects in memory. For
example, consider the below Python statements:

>>> a = 'abc'
>>> b = input("Enter a string: ")
Enter a string: abc
>>> a == b
True
>>> a is b
False
Here, both a and b have the same value 'abc' but they point to different objects.

Question 14

Given str1 = "Hello", what will be the values of:

(a) str1[0]

(b) str1[1]

(c) str1[-5]

(d) str1[-4]

(e) str1[5]

Answer

(a) H
(b) e

(c) H

(d) e

(e) IndexError: string index out of range

Explanation

\begin{matrix} \underset{-5}{\overset{0}\bold{H}} & \underset{-


4}{\overset{1}\bold{e}} & \underset{-3}{\overset{2}\bold{l}} & \underset{-
2}{\overset{3}\bold{l}} & \underset{-1}{\overset{4}\bold{o}}
\end{matrix}−5H0−4e1−3l2−2l3−1o4

Question 15

If you give the following for str1 = "Hello", why does Python report error?

str1[2] = 'p'

Answer

Python reports error because strings are immutable and hence item assignment is not supported.

Question 16

What will the result given by the following?

(a) type (6 + 3)

(b) type (6 -3)

(c) type (6 *3)

(d) type (6 / 3)

(e) type (6 // 3)

(f) type (6 % 3)

Answer

(a) type (6 + 3)
⇒ int + int
⇒ int
So the result is int.
(b) type (6 -3)
⇒ int - int
⇒ int
So the result is int.

(c) type (6 * 3)
⇒ int * int
⇒ int
So the result is int.

(d) type (6 / 3)
⇒ int / int
⇒ float
So the result is float.

(e) type (6 // 3)
⇒ int // int
⇒ int
So the result is int.

(f) type (6 % 3)
⇒ int % int
⇒ int
So the result is int.

Question 17

What are augmented assignment operators? How are they useful?

Answer

Augmented assignment operators combine the impact of an arithmetic operator with an


assignment operator. For example, to add the value of b to the value of a and assign the result
back to a then instead of writing:

a=a+b

we can write

a += b.

Augmented assignment operators are useful as they provide a shorthand way by combining the
arithmetic and assignment operators.

You might also like