0% found this document useful (0 votes)
7 views

Grade 11 CS ch-7 Data Handling C.W notes

The document provides an overview of Python's built-in core data types, including mutable and immutable types, and discusses key attributes of variables. It explains the differences between implicit and explicit type conversions, as well as equality versus identity comparisons in Python. Additionally, it covers error types, including syntax, semantic, and logical errors, along with the distinction between errors and exceptions.

Uploaded by

varshaashwin1230
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Grade 11 CS ch-7 Data Handling C.W notes

The document provides an overview of Python's built-in core data types, including mutable and immutable types, and discusses key attributes of variables. It explains the differences between implicit and explicit type conversions, as well as equality versus identity comparisons in Python. Additionally, it covers error types, including syntax, semantic, and logical errors, along with the distinction between errors and exceptions.

Uploaded by

varshaashwin1230
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

GRADE : XI

SUB : COMPUTER SCIENCE CH-7 DATA HANDLING C.W

1. What are the built-in core data types of Python?

The built-in core data types of Python are:

i) Numbers

ii) String

iii) List

iv) Tuple

v) Dictionary

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

Two integer types are supported by Python. They are:

1. Integers (signed)

2. Booleans

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

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

4. What are three internal key-attributes of a value-variable in Python? Explain with example.
The three internal key-attributes of a value-variable in Python are:
1. Type
2. Value
3. Id
1) type :-

It determined the type of object by using function type()

Example = >>>a = 5

>>>type(a)

<class ‘int’>
2)value :-

It is data item contained in the object .it can use by print statement.

Example = >>>a = “python”

>>>print (a)

‘python’
3)id :-

It refers the memory location of the object. It can use by function id()
Example = >>>a = 8

>>>id (a)

308829545
5. Is it true that if two objects return True for is operator, they will also return True for ==
operator?
yes, it is always true.
6.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"

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.

1. 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.
2. For 'a' and "a", both equality (==) and is operator returns True as their values are same
7.What is the difference between implicit type conversion and explicit type conversion?

Implicit Type Conversion Explicit Type Conversion

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


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

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


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)

8. 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?)

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.

9. Write following expressions in Python:


(a) 1/3 b2h - 1/3*b*b*h
2
(b) A=π r h - math.pi * r * r * h
(c) 1/3 A=π r 2 h - 1 / 3 * math.pi * r * r * h

(d) x= √ ( x 2−x 1 ) ²+ ( y 2− y 1 ) ² - math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)



(e) (x-h)²+(y-k)² = r² - (x - h) ** 2 + (y - k) ** 2 == r ** 2

10. Evaluate the following for each expression that is successfully evaluated, determine its value and type
for unsuccessful expression, state the reason.
(a) len("hello") == 25/5 or 20/10
(b) 3 < 5 or 50/(5 - (3 + 2))
(c) 50/(5 - (3 + 2)) or 3 < 5
(d) 2 * (2 * (len("01")))
Answer

⇒ 5 == 25/5 or 20/10
(a) len("hello") == 25/5 or 20/10

⇒ 5 == 5 or 2
⇒ True or 2
⇒ True
The type of result is Boolean.

⇒ True or 50/(5 - (3 + 2)) [∵ first operand is True, second operand is not evaluated so no division by 0
(b) 3 < 5 or 50/(5 - (3 + 2))

⇒ True
error happens]

The type of result is Boolean.

⇒ 50/(5 - 5) or 3 < 5
(c) 50/(5 - (3 + 2)) or 3 < 5

⇒ 50/0 or 3 < 5
⇒ Division by Zero Error
As the denominator of or operator's first operand is 0, Division by Zero error occurs.

⇒ 2 * (2 * 2)
(d) 2 * (2 * (len("01")))

⇒2*4
⇒8
The type of result is Integer.

11. A program runs to completion but gives an incorrect result. What type of error would have caused it?
Answer
Logical errors can make a program run till completion but give incorrect result.

12. In Python, strings are immutable while lists are mutable. What is the difference?
Answer
In Python, strings are immutable means that individual letter assignment for strings is not allowed. For
example:
name='hello'
name[0] = 'p'
The above Python code will cause an error as we are trying to assign some value to an individual letter of a
string.
Lists are mutable in Python means that we can assign values to individual elements of a list. For example:
a = [1, 2, 3, 4, 5]
a[0] = 10
The above Python code will work correctly without any errors as Lists are mutable in Python.

13. How does the // operator differ from the / operator? Give an example of where // would be needed.?
Answer
The Division operator (/) divides its first operand by second operand and always returns the result as a
float value whereas Floor Division operator (//) divides its first operand by second operand and truncates
the fractional part of the result and returns it as an int value. Floor Division operator is useful in situations
where we only need the integer part of the division operation result.

14. What are main error types? Which types are most dangerous and why?
Answer
The types of errors are:
1. Compile Time Errors (Syntax errors and Semantic Errors)
2. Runtime Errors
3. Logical Errors
Logical Errors are the most dangerous as they are hardest to prevent, find and fix.

15. Correct any false statements:


(a) Compile-time errors are usually easier to detect and to correct than run-time errors.
(b) Logically errors can usually be detected by the compiler.
Answer
(a) The statement is correct.
(b) The statement is incorrect. The correct statement should be:
Logical errors cannot be detected by the compiler.

16. Differentiate between a syntax error and a semantics error.


Answer

Syntax Error
Semantics Error

Syntax errors occurs when the rules of the Semantic errors occur when the statement
programming language are violated. are not meaningful.

Example:
Example: x*y=z
x = false
17. Differentiate between a syntax error and a logical error in a python program. When is each type of error
likely to be found?

Syntax Errors occur when we violate the rules of Logical Errors occur due to our mistakes in
writing the statements of the programming programming logic.
language.

Program fails to compile and execute. Program compiles and executes but doesn't
give the desired output.

Logical errors need to be found and corrected


Syntax Errors are caught by the compiler. by people working on the program.

18. What is the difference between an error and exception?


Answer
An Error is a bug in the code that causes irregular output or stops the program from executing whereas an
Exception is an irregular unexpected situation occurring during execution on which programmer has no
control.

You might also like