Data Handling || Type B || Sumita Arora || Class 11 || Computer science || Information practices || Solution
(i) bool (0)
(ii) bool (str(0)) ? Justify the outcome.
2. What will be the output, if input for both the statements is 5+4/2?
6 == input ("Value 1 :")
6 == int(input ("value 2:"))
Q3. Following code has an expression with all integer values. Why is the result in floating point form?
a, b, c = 2, 3, 6
d = a + b * c / b
print(d)
Q4. What will following code print?
(a)
a = va = 3
b = va = 3
print (a, b)
(b)
a = 3
b = 3.0
print (a == b)
print (a is b)
Q5. What will be output produced by following code? State reason for this output.
(b). What will be output produced by following code? State reason.
a = 5 - 4 - 3
b = 3 ** 2 ** 3
print(a)
print(b)
(c). What would be the output produced by following code? Why?
a, b, c = 0.1
d = 0.3
e = a + b + c - d
f = a + b + c == d
print(e)
print(f)
Q6. What will be the output of following Python code?
(a)
b = 7.4
c = 1
a -= b
print(a, b)
a *= 2 + c
print(a)
b += a * c
print(b)
x , y = 4, 8
z = x /y * y
print(z)
Q7. Make change in the expression for z of previous question so that the output produced is zero. You cannot change the operators and order of variables.
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
where are the questions after this???
ReplyDeleteGo to type C option .
Deletehey buddy
ReplyDeleteYes.
DeleteI'm Anonymous.
ReplyDeleteOk, How can I help you
Deletew,x,y,z=True,4,-6,2
ReplyDeleteresult=-(x+z)<y or x**z<10
print(result)
What is the output please tell
False
Delete>>>
hello can u hrlp me with a question
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )