0% found this document useful (0 votes)
70 views7 pages

Class 11 - Data Handling - Solution

The document provides a comprehensive overview of data handling in Python for Class 11 Computer Science, covering various types of errors, operators, and examples of code snippets. It explains compile time errors, run time errors, logical errors, and the use of different operators in Python. Additionally, it includes practical examples for calculating areas, volumes, and handling user inputs.
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)
70 views7 pages

Class 11 - Data Handling - Solution

The document provides a comprehensive overview of data handling in Python for Class 11 Computer Science, covering various types of errors, operators, and examples of code snippets. It explains compile time errors, run time errors, logical errors, and the use of different operators in Python. Additionally, it includes practical examples for calculating areas, volumes, and handling user inputs.
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/ 7

Solution

DATA HANDLING

Class 11 - Computer Science


Section A
1. (a) Compile time errors
Explanation: Compile time errors
2.
(d) Run time
Explanation: Run time
3.
(d) Strings
Explanation: Strings
4.
(c) All of these
Explanation: All of these
5.
(b) Numbers
Explanation: Numbers
6. (a) a**b
Explanation: The power operator in python is a**b, i.e., 2**3 = 8.
7.
(d) AttributeError
Explanation: AttributeError: Raised in case of failure of attribute reference or assignment.
8.
(c) Debugger
Explanation: Debugger
9. (a) OverflowError
Explanation: OverflowError: Raised when a calculation exceeds maximum limit for a numeric type.
10.
(c) imaginary part
Explanation: imaginary part
Section B
11. i. False
ii. True

12. a = int ( input ( " Enter a : "))


b = 0
c = a/b # Division by zero

Here, a/b will generate the run-time error.


13. i. z = a / (a + b) - (d * d)
ii. z = (x * * 2) + (y * * 3)
14. i. p / q + a - c valid
ii. q (a + b - z / 4) invalid because operator missing between q and a
iii. p / q + a - c valid
iv. x / y + p * a / b valid
v. a * + b invalid because use of two operator together
vi. a // + b * c * 2 valid

1/7
15. The * operator will be performed before //. Though both have same priority but in this expression * is prior to //.
A = 12 // 5 + 5 // 7 + 8 - 2 + 4 // 2
= 2 + 5 // 7 + 8 - 2 + 4 // 2
= 2 + 0 + 8 - 2 + 4 // 2
=2+0+8-2+2
=2+0+8-2
= 10
16. prod = int(input("Enter the original amount of the product: "))
gst = int(input("Enter the percentage of GST on that product: "))
GST_Amount = (prod * gst) / 100
Net_price = prod + GST_Amount
print(f"Original Price: ₹{prod}")
print(f"GST Amount: ₹{GST_Amount}")
print(f"Net Price: ₹{Net_price}")
17. The syntax errors are

a = int (input (" Enter first number : "))


b = int (input (" Enter second number : "))
print(" a = ", a, end = " ", "b = ", b)
c = a + b
print c

18. i : 10
j : 15
k : 13.0
l : 17.0
m : 8.0
n : 149.0
19. a = 15
b = 15
c = False
Section C
20. i. 21
ii. -1
iii. 6
iv. False
v. False
vi. 68.5
vii. 86
viii. True
21. Compile time errors are displayed by interpreter and compiler. If compiler displays this error then program will not be run. Before
to run the program, it must fix all compile time errors. Compile time error further classified into two types as:
i. Syntax Error: Like any other languages, Python language has some rules that specify how a program is to be written. This is
called syntax. When a format set of rules defined for writing a program in a particular language is not following then error
raised is know as syntax error.
ii. Semantic Error: This type of error occurs when wrong or improper statements are used. Those statements are meaningless.
22. i. A = 10 * 4 // 2 + 4 - 2 // 2 + 4 - 3 + 5 // 8
= 40 // 2 + 4 - 2 // 2 + 4 - 3 + 5 // 8
= 20 + 4 - 2 // 2 + 4 - 3 + 5 // 8
= 20 + 4 - 1 + 4 - 3 + 5 // 8
= 20 + 4 - 1 + 4 - 3 + 0
= 24 - 1 + 4 - 3 + 0
= 23 + 4 - 3

2/7
= 27 - 3
= 24
ii. A = 5 + 6 // 3 + 10 * 3 // 4 + 2 + 3 // 4
= 5 + 2 + 10 * 3 // 4 + 2 + 3 // 4
= 5 + 2 + 30 // 4 + 2 + 3 // 4
=5+2+7+2+0
=7+7+2
= 16
iii. A = 5 * 5 + 4 // 5 + 15 - 9 // 2 + 10
= 25 + 4 // 5 + 15 - 9 // 2 + 10
= 25 + 0 + 15 - 4 + 10
= 40 - 4 + 10
= 36 + 10
= 46
23. A logical error is a mistake in a program's source code that results in incorrect or unexpected behaviour. It may simply produce the
wrong output or may cause a program to crash while running. Some commonly made logical errors are:
i. Using the wrong variable name.
ii. Indenting a block to the wrong level.
iii. Getting operator precedence wrong.
iv. Making a mistake in a boolean expression,
e.g. x = 2
y=4
z = x*y/2
print ("Average:", z)
Output
Average: 4
Above code produces the output 4 but expected output is 3. This code is syntactically correct but logically wrong.
The error is that the formula to find the average of the numbers is incorrect. Correct formula is
a+b
avg = 2

24. In Python, operators are used to specify operations to be performed on the variables and gives resultant values. An operand is an
entity on which an operator works.
e.g. x + y
Here, + is an operator and x, y are operands. On the use of operands, Python operators are divided in these types:
i. Unary Operators: These operators that need single operand to form an expression are known as unary operators, e.g. unary
plus (+), unary minus (-) etc.
ii. Binary Operators: These operators that need two operands to form an expression are known as binary operators.
Furthermore, operators are classified into these types:
i. Arithmetic operators
ii. Relational operators
iii. Logical operators
iv. Identity operators
v. Bitwise operators
vi. Membership operators

25. Syntax Error Logical Error

It is an error in the syntax of a sequence of characters or tokens that is It is an error in a program that causes it to operate
(i)
intended to be written in a particular programming language incorrectly but not to terminate abnormally.

A logical error occurs due to a fault in the


(ii) A syntax error occurs due to fault in the program syntax.
algorithm.

In compiled languages, the compiler indicates the syntax error with The programmer has to detect the error by
(iii)
the location and what the error is. himself.

3/7
(iv) It is easier to identify a syntax error. It is comparatively difficult to identify a logical
error.

(v) e.g. Incorrect parentheses e.g. Improper intartation

26. print("Calculate the Volume of Sphere")


radius = int(input("Enter the radius of a sphere: "))
print("Radius of Sphere:", radius)
# Volume of sphere
volume = (4 / 3) * 3.14 * (radius ** 3)
print("Volume of Sphere:", volume)
print("\nCalculate the Volume of Hemisphere")
radius1 = int(input("Enter the radius of a hemisphere: "))
print("Radius of Hemisphere:", radius1)
# Volume of hemisphere
volume1 = (2 / 3) * 3.14 * (radius1 ** 3)
print("Volume of Hemisphere:", volume1)

Output
Calculate the volume of Sphere
Enter the radius of a sphere : 5
Radius of Sphere : 5
Volume of Sphere : 523.3333333333334
Calculate the Volume of Hemisphere
Enter the radius of a hemisphere : 4
Radius of Hemisphere : 4
Volume of Hemisphere : 133.97333333333333

27. km = float(input("Enter the distance in kilometers: "))


print("Distance in kilometers:", km)
meters = km * 1000
print("Distance in meters:", meters)

Output
Enter the distance in Km : 2.5
Distance in Km : 2.5
Distance in meters : 2500.0

28. a = float(input('Enter the First side of a Triangle: '))


b = float(input('Enter the Second side of a Triangle: '))
c = float(input('Enter the Third side of a Triangle: '))
# Calculate the Perimeter
Perimeter = a + b + c
# Calculate the semi-perimeter
s = (a + b + c) / 2
# Calculate the area
Area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
print("\nThe perimeter of Triangle = %.2f" % Perimeter)
print("The Semi Perimeter of Triangle = %.2f" % s)
print("The Area of a Triangle is %.2f" % Area)

Output
Enter the first side of a triangle : 13
Enter the second side of a triangle : 12
Enter the third side of a triangle : 5

4/7
29. a. r = int(input("Enter radius of the circle")) area = 22/7 * (r ** 2) print("Area of the circle is", area)
b. a = int(input("Enter first number"))
b = int(input("Enter second number"))
c = int(input("Enter third number"))
a=a+b
b=b+c
print("Value of a is", a)
print("Value of b is", b)
print("Value of c is", c)
30. i. Output
x > y is False
x < y is True
x == y is False
x ! = y is True
x > = y is False
x < = y is True
ii. Output
x + y = 23
x - y = 15
x * y = 76
x / y = 4.75
x // y = 4
x ** y = 130321
31. In this case, the program does not give any error but still gives an incorrect output, it is due to logical errors. These errors occur
due to mistakes of the programmer. This is the most difficult task to find and debug a logical error.
For example, when a wrong formula is used to calculate any mathematical expression gives logical error.
Some Python logical errors include
i. Using the wrong variable name
ii. Indenting a block to the wrong level
iii. Getting operator precedence wrong
iv. Making a mistake in a boolean expression
e.g. a = 17
b = 11
c = 12
avg = (a * b) / (c + 3)
print ( " The average is : " , avg)
The above program, gives the result 12.4666667, but the expected output is 13.3333333.
(a+b+c)
Here is logical error that formula to find the average of numbers should be avg = 3

32. a. NameError exception raised when a identifier is not found in the local or global namespace.
b. RuntimeError exception raised when a generated error does not fall into any category.
c. OverflowError exception raised when result of an arithmetic operation is too large to be represented.
d. IOError exception raised when an input/output operation fails.
33. Arithmetic operators help us to perform various arithmetic calculations. The arithmetic operators are explained in the table below.
Let's assume value of a = 2 and b = 3
Operator Description Example

+ Addition: Adds values on either side of the operator. a + b results in 5

a - b results in
- Subtraction: Subtracts right-hand operand from left-hand operand.
-1

* Multiplication: Multiplies values on either side of the operator. a * b results in 6

/ Division: Divides left-hand operand by right-hand operand. a/b results in 0

5/7
% Modulus: Divides left-hand operand by right-hand operand and returns remainder. a % b results in
2

** Exponent: Performs exponential (power) calculation on operators. a**b results in 8

11/2 results in 5
Floor Division: The division of operands where the result is the quotient in which the digits after
// 11.0/2.0 results
the decimal point are removed
in 5.0

34. l = int (input("Enter the length:"))


b = int (input("Enter the breath:"))
print ("length:",l)
print ("Breath:",b)
p = 2 * (l+b)
print ("perimeter of the rectangle:",p)

Output
Enter the length : 6
Enter the breath : 4
Length : 6
Breath : 4
Perimeter of the rectangle : 20

35. time = float(input("Input time in seconds: "))


day = time // (24 * 3600)
time = time % (24 * 3600)
hour = time // 3600
time %= 3600
minutes = time // 60
time %= 60
seconds = time
print("Days:", day)
print("Hours:", hour)
print("Minutes:", minutes)
print("Seconds:", seconds)

Output
Input time in seconds: 360425060
Days : 4171.0
Hours : 14.0
Minutes : 4.0
Seconds : 20.0
36. An error is a flaw, fault or failure in a computer program that causes it to produce an incorrect or unexpected result or to behave in
unintended ways. During compilation, when an error occurs, interpreter displays an error message on the screen. Run time errors:
These errors occur during program execution and most of the time result in abnormal absorption of the program. These errors
occur mostly due to some very unobvious values being generated by some previously executed module of the program, and those
values being used in the current module, e.g.
division by zero
non-existing file being accessed.
a value that has been deleted being used in present module
37. choice = int(input("Enter choice: 1 - Triangle, 2 - Square, 3 - Rectangle")) if choice == 1:
base = float(input("Enter base of triangle"))
height = float(input("Enter height of triangle"))
area = 0.5 * base * height

6/7
a = float(input("Enter the other 2 sides"))
b = float(input("Enter the other 2 sides"))
peri = a + b + base
print("Area of triangle =", area)
print("Perimeter of triangle =", peri)
elif choice == 2:
side = float(input("Enter side of square"))
area = side * side
peri = 4 * side
print("Area of square =", area)
print("Perimeter of square =", peri)
elif choice == 3:
length = float(input("Enter length of rectangle"))
breadth = float(input("Enter breadth of rectangle"))
area = length * breadth
peri = 2 * (length + breadth)
print("Area of rectangle =", area)
print("Perimeter of rectangle =", peri) else:
print("Done")

7/7

You might also like