Data Handling || Type B || Sumita Arora || Class 11 || Computer science || Information practices || Solution


a = 12
b = 7.4
c = 1
a -= b
print(a, b)
a *= 2 + c
print(a)
b += a * c
print(b)



 
 
 


Q9. Consider the following code segment:

a = input()
b = int(input())
c = a + b
print(c)

When the program is run, the user first enters 10 and then 5, it gives an error. Find the error, its reason and correct it.




Q10. Consider the following code segment:

a = input("Enter the value of a:")
b = input("Enter the value of b:")
print(a + b)

If the user runs the program and enters 11 for a and 9 for b then what will the above code display




Q11. Find out the error and the reason for the error in the following code. Also, give the corrected code.

a, b = "5.0", "10.0"
x = float (a/b)
print(x)





Q12. When this program is run, the following output is generated (note that input entered by the user is shown in bold):

Enter the length of the first side: 3
Enter the length of the second side: 4
Traceback (most recent call last):
h = sqrt(a * a + b * b)
NameError: name 'sqrt' is not defined

Why is this error occurring? How would you resolve it?





Q13. After adding import math to the code given above (before question 12), what other change(s) are required in the code to make it fully work?




Q14. Which of the following expressions will result in an error message being displayed when a program containing it is run?

(a) 2.0/4
(b) "3" + "Hello"
(c) 4 % 15
(d) int("5") / float("3")
(e) float("6"/"2")





Q15. Following expression does not report an error even if it has a sub-expression with ‘divide by zero’ problem:
3 or 10/0
What changes can you make to above expression so that Python reports this error?






Q15. What is the output produced by following code?

a, b = bool (0), bool (0.0)
c, d =str (0), str (0.0)
print (len(a), len(b))
print (len(c), len(d))




Q16. Given a string s = "12345". Can you write an expression that gives sum of all the digits shown inside string i.e. the program should be able to produce the result as 15 (1 + 2 + 3 + 4 + 5).





Q17. Predict the output if ‘e’ is given input as ‘True’

a = True
b = 0 < 5
print (a == b)
print (a is b)
c  = str (a)
d = str (b)
print (c == d)
print (c is d)
e = input ("Enter : ")
print (c == e)
print (c is e)





Q18. Find the errors:

(a)
name = "HariT"
print (name)
name[2] = 'R'
print (name)

(b)
a = bool(0)
b = bool(1)
print (a == false)
print (b == true)

(c)
print (type (int('123')))
print (type(int ("Hello")))
print (type (str("123.0")))

(d)

pi = 3.14
print (type (pi))
print (type ("3.14"))
print (type (float ("3.14")))
print (type (float("three point fourteen")))

(e)
print ("Hello" + 2)
print ("Hello" + '2')
print ("Hello" * 2)

(f)
print ("Hello" / 2)
print ("Hello" / 2)



Q19. What will be the output produced?

(a)
x, y, z = True, False, False
a = x or (y and z)
b = (x or y) and z
print(a, b)

(b)
x, y = '5', 2
z = x + y
print(z)

(c)
s = 'Sipo'
s1 = s + '2'
s2 = s * 2
print(s1)
print(s2)

(d)
w,x, y, z = True , 4, -6, 2
result = - (x + z) < y or x ** z < 10
print(result)





Q20. Program is giving a weird result of "0.50.50.50.50.50.50....” Correct it so that it produces the correct result which is the

probability value (input as 0.5) times 150.

probability = input("Type a number between 0 and 1: ")
print("Out of 150 tries, the odds are that only", (probability * 150), "will succeed. ")

[Hint. Consider its datatype.)




Q21. Consider the code given below:

import random
r = random.randrange (100, 999, 5)
print(r, end = ' ')
r = random.randrange(100, 999, 5)
print(r, end = ' ')
r = random.randrange (100, 999, 5)
print(r)

Which of the following are the possible outcomes of the above code? Also, what can be the maximum and minimum number

generated by line 2?

(a) 655, 705, 220
(b) 380, 382, 505
(c) 100, 500, 999
(d) 345, 650, 110




Q22. Consider the code given below:

import random
r = random.randint (10, 100) - 10
print(r, end = ' ')
r = random.randint (10, 100) - 10
print(r, end = ' ')
r = random.randint (10, 100) - 10
print(r)

Which of the following are the possible outcomes of the above code? Also, what can be the maximum and minimum number

generated by line 2?

(a) 12 45 22
(b) 100 80 84
(c) 101 12 43
(d) 100 12 10




Q23. Consider the code given below:

import random
r= random.random() * 10
print(r, end = ' ')
r = random.random() * 10
print(r, end ='')
r = random.random() * 10
print(r)

Which of the following are the possible outcomes of the above code? Also, what can be the maximum and minimum number

generated by line 2?

(a) 0.5 1.6 9.8
(b) 10.0 1.0 0.0
(c) 0.0 5.6 8.7
(d) 0.0 7.9 10.0





Q24. Consider the code given below:

import statistics as st
v = [7, 8, 8, 11, 7, 7]
m1 = st.mean(v)
m2 = st.mode(v)
m3 = st.median(v)
print(m1, m2, m3)

Which of the following is the correct output of the above code?

(a) 7 8 7.5
(b) 8 7 7
(c) 8 7 7.5
(d) 8.5 7 7.5

9 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post