Chem
Chem
Chem
SECTION - C
29 i. Convert: a) (1234.56)10 = (?)16 3
b) (476)8 = (?)2
ii. Arrange the following in ascending order of memory capacity:
TB , Byte, KB, Nibble, PB, MB, GB
30 Predict the output of the following code fragments:
i)
x = 10
y=0
while x > y:
print (x, y)
x=x-1
y=y+1 3
ii)
keepgoing = True
x=100
while keepgoing :
print (x)
x = x - 10
if x < 50 :
keepgoing = False
31 i. Evaluate the following expressions:
a) 6 * 3 + 4**2 // 5 – 8
b) 10 > 5 and 7 > 12 or not 18 > 3
3
ii. Find and write the output of the following python code:
x=”abcdef”
i=”a”
while i in x:
print(i, end=” “)
SECTION - D
32 i. What is the output produced by the following code? ii. Predict the output of the
x=1 following code fragments:
if x > 3 : (a)
if x > 4 : count = 0
print ("A", end = ' ') while count < 10 :
else : print ("Hello") 4
print ("B", end = ' ') count += 1
elif x < 2:
if (x != 0) : (b)
print ("C", end = ' ') x = 10
print ("D") y=5
for i in range (x - y * 2) :
print ("%", i)
33 i. What is the output of the following lines of code? If ii. What is following code
it returns error how will you correct it? doing? What would it print
if int('zero') == 0 : for input as 3?
print ("zero") n = int (route "Enter an 4
elif str(0) == 'zero' : integer : "))
print (0) if n < 1 :
elif str(0) == '0' : print ("invalid value")
print (str(0)) else :
else : for i in range (1, n + 1) :
print ("none of the above") print (i * i)
34 Expressions in programming are like formulas in mathematics: both use values (in
Python literals and names bound to values) to compute a result. But unlike
mathematics, expressions in Python can compute results of a wide variety of types
(e.g., boolean and string) not just mathematical results. We classify these operators,
both symbols and identifiers, into four categories and examine them separately:
Arithmetic (+ -* / // % **), Relational: (== != < > <= >= is in), Logical (and not or), and
finally Bitwise (& | ~ ^ << >>) When two or more operators share an operand with
the same precedence, such as a * b / c, the expression is evaluated according to
associativity. When all of the operators in an expression have the same precedence, the
expression is evaluated using left to right associativity. Now, since the ** operator has
right-to-left associativity, a ** b ** c will be evaluated as a ** (b ** c). For exponentiation,
the expression on the right is evaluated first. On the other hand, since the * operator 4
has left-to-right associativity, a * b * c is treated as (a * b) * c. For multiplication, the
expression on the left is evaluated first.
i.
if a =1 and b =2 and c =3 then a **b ** c evaluate to :
a) 1 b) 8 c) 9 d) 15
ii.
if a= 3 and b = 5 then ( a > b and b>a) evaluate to :
(a)True b) False c) True and True d) None of these
iii.
% is known as the modulus operator and if a =13 and b =2 then a % b evaluate to __.
(a) False , 0 b) True , 6 c) True , None d) None of These
if temp < 32 :
print ("ice")
elif temp < 212 : 4
print ("water")
else :
print ("steam")
OR
b. (i)What is the purpose of range() function? Give one example. (2 ½ )
(ii) Write a function to print the table of a given number. The number has to be
entered by the user. (2 ½)
37. Write the output of (b)
the following: (3) num1, num2 = 2, 6
(a) num1, num2 = num2, num1 + 2 (d) Write a program to enter
num1 = 4 print (num1, num2) two integers and perform all
num2 = num1 + 1 arithmetic operations on
num1 = 2 them. (2)
print (num1, num2) (c)
num1, num2 = 2, 3
num3, num2 = num1, num3 + 1
print (num1, num2, num3)
OR
Find the errors: 5
(a) (c) (e)
name = "HariT" print (type (int('123'))) print ("Hello" + 2)
print (name) print (type(int ("Hello"))) print ("Hello" + '2')
name[2] = 'R' print (type (str("123.0"))) print ("Hello" * 2)
print (name)
(d)
(b) pi = 3.14
a = bool(0) print (type (pi))
b = bool(1) print (type ("3.14"))
print (a == false) print (type (float ("3.14")))
print (b == true) print (type (float("three point
fourteen")))