Page 7 - PYTHON-12
P. 7
23. What is implicit conversion in Python? (2)
Ans. Implicit conversion in Python is also known as coercion. This conversion means that the data type conversion
is done automatically during run-time and is not instructed by the programmer.
For example:
x=9
y=99.0
z=x+y
print(z)
So, it gives the output 108.0 as implicit conversion is performed to convert it into float automatically.
24. Answer the following using built-in functions only. (2)
If T1= (3,5,7,9) and T2 = (1,2,4,6), then
I. (a) Write a statement to convert T1 to a list.
OR
(b) Write a statement to find the maximum value from tuple T2.
II. (a) Write a statement to find the sum of all elements in T1.
OR
(b) Write a statement to find the length of T2.
Ans. I. (a) L1 = list(T1)
OR
(b) Max_Value = max(T2)
II. (a) T_Sum= sum(T1)
OR
(b) T2_length = len(T2)
25. Identify the correct output(s) of the following code. Also write the minimum and the maximum possible values
of the variable val. (2)
import random
s =[100,75,10,125]
val =random.randint(0,3)
for j in range(val):
print(s[j],"$$")
(a) 100$$ (b) 100$$
75$$ 99$$
10$$
(c) 150$$ (d) 125$$
100$$ 10$$
Ans. The correct output is:
(a) 100$$
75$$
10$$
The minimum value of variable val is 0 and the maximum value of variable val is 3.
26. The following code is intended to check whether a number is positive or not; if negative, then make it a
positive number. However, there are syntax and logical errors in the code. Rewrite it after removing all
errors. Underline all the corrections made. (2)
DEF check_num():
num = input("Enter a number:")
if (abs(num)= num):
print"You entered a positive number"
else:
num=*-1
print"Number made positive:"num
check_num()
A.38 Computer Science with Python–XII