CSC201_OBJ_Questions.txt
[MAX]25[/MAX]
[QUESTIONS]
<1>What is the output of the following expression:
print(4.00/(2.0+2.0))1>
<2>Consider the expression given below.
The value of X is:
X = 2+9*((3*12)-8)/102>
<3>Which of the following expressions involves coercion when evaluated in Python?3>
<4>What is the value of the following expression:
24//6%3, 24//4//24>
<5>What is the value of the expression:
float(4+int(2.39)%2)5>
<6>Which of the following expressions results in an error?6>
<7>What is the value of the expression:
4+2**5//107>
<8>Is Python case sensitive when dealing with identifiers?8>
<9>What is the maximum possible length of an identifier?9>
<10>Which of the following is an invalid variable?10>
<11>Why are local variable names beginning with an underscore discouraged?11>
<12>All keywords in Python are in12>
<13>Which of the following cannot be a variable?13>
<14>What is the output of the following?
i = 0
while i < 5: print(i)
i += 1
if i == 3:
break
else: print(0)14>
<15>What is the output of the following?
i = 0
while i < 3: print(i)
i += 1
else: print(0)15>
<16>To add a new element to a list we use which command?16>
<17>To insert 5 to the third position in list1, we use which command ?17>
<18>To remove string “hello” from list1, we use which command?18>
<19>Suppose list1 is [1, 3, 2], What is list1 * 2 ?19>
<20>Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?20>
<21>Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.21>
<22>The result of the expression shown below is:
4^1222>
<23>What is the value of this expression:
bin(10-2)+bin(12^4)23>
<24>What is the output of the code show
below if a=10 and b=20
a=10
b=20
a=a^b
b=a^b
a=a^b
print(a,b)24>
<25>What is the value of the expression:
~10025>
[/QUESTIONS]
[OPTIONS]
<1>Error
1.0
1.00
11>
<2>30.0
30.8
28.4
27.22>
<3>4.7–1.5
7.9*6.3
1.7%2
3.4+4.63>
<4>(1,3)
(0,3)
(1,0)
(3,1)4>
<5>5.0
5
4.0
45>
<6>float(‘10’)
int(‘10’)
float(’10.8’)
int(’10.8’)6>
<7>3
7
77
07>
<8>yes
no
machine dependent
none of the above8>
<9>31 characters
63 characters
79 characters
none of the above9>
<10>my_string_1
1st_string
foo
_10>
<11>they areused to indicate a private variables of a class
they confuse the interpreter
they are used to indicate global variables
they slow down execution11>
<12>lower case
UPPER CASE
Capitalized
None of the above12>
<13>__init__
in
it
on13>
<14>0 1 2 0
0 1 2
error
none of the above14>
<15>0 1 2 3 0
0 1 2 0
0 1 2
error15>
<16>list1.add(5)
list1.append(5)
list1.addLast(5)
list1.addEnd(5)16>
<17>list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)17>
<18>list1.remove(“hello”)
list1.remove(hello)
list1.removeAll(“hello”)
list1.removeOne(“hello”)18>
<19>[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]19>
<20>0
4
1
220>
<21>OR
AND
XOR
NOT21>
<22>2
4
8
1222>
<23>0b10000
0b10001000
0b1000b1000
0b10000b100023>
<24>10 20
10 10
20 10
20 2024>
<25>101
-101
100
-10025>
[/OPTIONS]
[ANSWERS]
<1>1.01>
<2>27.22>
<3>1.7%23>
<4>(1,3)4>
<5>4.05>
<6>int(’10.8’)6>
<7>77>
<8>yes8>
<9>none of the above9>
<10>1st_string10>
<11>they areused to indicate a private variables of a class11>
<12>None of the above12>
<13>in13>
<14>0 1 214>
<15>0 1 2 015>
<16>list1.append(5)16>
<17>list1.insert(3, 5)17>
<18>list1.remove(“hello”)18>
<19>[1, 3, 2, 1, 3, 2]19>
<20>220>
<21>XOR21>
<22>822>
<23>0b10000b100023>
<24>20 1024>
<25>-10125>
[/ANSWERS]
[EXPLANATION]
<1>The result of the expression shown above is 1.0 because print rounds off digits.1>
<2>The expression shown above is evaluated as: 2+9*(36-8)/10, which simplifies to give 2+9*(2.8), which is equal to 2+25.2 = 27.2. Hence the result of this expression is 27.2.2>
<3>Coercion is the implicit (automatic) conversion of operands to a common type. Coercion is automatically performed on mixed-type expressions. The expression 1.7 % 2 is evaluated as 1.7 % 2.0 (that is, automatic conversion of int to float).3>
<4>The expressions are evaluated as: 4%3 and 6//2 respectively. This results in the answer (1,3). This is because the associativity of both of the expressions shown above is left to right.4>
<5>The above expression is an example of explicit conversion. It is evaluated as: float(4+int(2.39)%2) = float(4+2%2) = float(4+0) = 4.0. Hence the result of this expression is 4.0.5>
<6>All of the above examples show explicit conversion. However the expression int(’10.8’) results in an error.6>
<7>The order of precedence is: **, //, +. The expression 4+2**5//10 is evaluated as 4+32//10, which is equal to 4+3 = 7. Hence the result of the expression shown above is 7.7>
<8>Case is always significant.8>
<9>Identifiers can be of any length.9>
<10>Variable names should not start with a number.10>
<11>As Python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class.11>
<12>True, False and None are capitalized while the others are in lower case.12>
<13>in is a keyword13>
<14>The else part of the code is not executed. if breaks the loop.14>
<15>The else part is executed when the condition in the while statement is false.15>
<16>We use the function append to
add an element to the list.16>
<17>Execute in the shell to verify.17>
<18>Execute in the shell to verify.18>
<19>Execute in the shell and verify.19>
<20>Execute in the shell to verify.20>
<21>Bitwise XOR gives 1 if either of the bits is 1 and 0 when both of the bits are 1.21>
<22>^ is the XOR operator. The binary form of 4 is 0100 and that of 12 is 1100. Therefore, 0100^1100 is 1000, which is equal to 8.22>
<23>The output of bin(10-2)= 0b1000 and that of bin(12^4) is ob1000. Hence the output of the above expression is: 0b10000b1000.23>
<24>The code shown above is used to swap the contents of two memory locations using bitwise X0R operator. Hence the output of the code shown above is: 20 10.24>
<25>Suppose we have an expression ~A. This is evaluated as: -A – 1. Therefore, the expression ~100 is evaluated as -100 – 1, which is equal to -101.25>
[/EXPLANATION]
[QUESTIONS]
<1>What is the output of the following expression:
print(4.00/(2.0+2.0))1>
<2>Consider the expression given below.
The value of X is:
X = 2+9*((3*12)-8)/102>
<3>Which of the following expressions involves coercion when evaluated in Python?3>
<4>What is the value of the following expression:
24//6%3, 24//4//24>
<5>What is the value of the expression:
float(4+int(2.39)%2)5>
<6>Which of the following expressions results in an error?6>
<7>What is the value of the expression:
4+2**5//107>
<8>Is Python case sensitive when dealing with identifiers?8>
<9>What is the maximum possible length of an identifier?9>
<10>Which of the following is an invalid variable?10>
<11>Why are local variable names beginning with an underscore discouraged?11>
<12>All keywords in Python are in12>
<13>Which of the following cannot be a variable?13>
<14>What is the output of the following?
i = 0
while i < 5: print(i)
i += 1
if i == 3:
break
else: print(0)14>
<15>What is the output of the following?
i = 0
while i < 3: print(i)
i += 1
else: print(0)15>
<16>To add a new element to a list we use which command?16>
<17>To insert 5 to the third position in list1, we use which command ?17>
<18>To remove string “hello” from list1, we use which command?18>
<19>Suppose list1 is [1, 3, 2], What is list1 * 2 ?19>
<20>Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?20>
<21>Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.21>
<22>The result of the expression shown below is:
4^1222>
<23>What is the value of this expression:
bin(10-2)+bin(12^4)23>
<24>What is the output of the code show
below if a=10 and b=20
a=10
b=20
a=a^b
b=a^b
a=a^b
print(a,b)24>
<25>What is the value of the expression:
~10025>
[/QUESTIONS]
[OPTIONS]
<1>Error
1.0
1.00
11>
<2>30.0
30.8
28.4
27.22>
<3>4.7–1.5
7.9*6.3
1.7%2
3.4+4.63>
<4>(1,3)
(0,3)
(1,0)
(3,1)4>
<5>5.0
5
4.0
45>
<6>float(‘10’)
int(‘10’)
float(’10.8’)
int(’10.8’)6>
<7>3
7
77
07>
<8>yes
no
machine dependent
none of the above8>
<9>31 characters
63 characters
79 characters
none of the above9>
<10>my_string_1
1st_string
foo
_10>
<11>they areused to indicate a private variables of a class
they confuse the interpreter
they are used to indicate global variables
they slow down execution11>
<12>lower case
UPPER CASE
Capitalized
None of the above12>
<13>__init__
in
it
on13>
<14>0 1 2 0
0 1 2
error
none of the above14>
<15>0 1 2 3 0
0 1 2 0
0 1 2
error15>
<16>list1.add(5)
list1.append(5)
list1.addLast(5)
list1.addEnd(5)16>
<17>list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)17>
<18>list1.remove(“hello”)
list1.remove(hello)
list1.removeAll(“hello”)
list1.removeOne(“hello”)18>
<19>[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]19>
<20>0
4
1
220>
<21>OR
AND
XOR
NOT21>
<22>2
4
8
1222>
<23>0b10000
0b10001000
0b1000b1000
0b10000b100023>
<24>10 20
10 10
20 10
20 2024>
<25>101
-101
100
-10025>
[/OPTIONS]
[ANSWERS]
<1>1.01>
<2>27.22>
<3>1.7%23>
<4>(1,3)4>
<5>4.05>
<6>int(’10.8’)6>
<7>77>
<8>yes8>
<9>none of the above9>
<10>1st_string10>
<11>they areused to indicate a private variables of a class11>
<12>None of the above12>
<13>in13>
<14>0 1 214>
<15>0 1 2 015>
<16>list1.append(5)16>
<17>list1.insert(3, 5)17>
<18>list1.remove(“hello”)18>
<19>[1, 3, 2, 1, 3, 2]19>
<20>220>
<21>XOR21>
<22>822>
<23>0b10000b100023>
<24>20 1024>
<25>-10125>
[/ANSWERS]
[EXPLANATION]
<1>The result of the expression shown above is 1.0 because print rounds off digits.1>
<2>The expression shown above is evaluated as: 2+9*(36-8)/10, which simplifies to give 2+9*(2.8), which is equal to 2+25.2 = 27.2. Hence the result of this expression is 27.2.2>
<3>Coercion is the implicit (automatic) conversion of operands to a common type. Coercion is automatically performed on mixed-type expressions. The expression 1.7 % 2 is evaluated as 1.7 % 2.0 (that is, automatic conversion of int to float).3>
<4>The expressions are evaluated as: 4%3 and 6//2 respectively. This results in the answer (1,3). This is because the associativity of both of the expressions shown above is left to right.4>
<5>The above expression is an example of explicit conversion. It is evaluated as: float(4+int(2.39)%2) = float(4+2%2) = float(4+0) = 4.0. Hence the result of this expression is 4.0.5>
<6>All of the above examples show explicit conversion. However the expression int(’10.8’) results in an error.6>
<7>The order of precedence is: **, //, +. The expression 4+2**5//10 is evaluated as 4+32//10, which is equal to 4+3 = 7. Hence the result of the expression shown above is 7.7>
<8>Case is always significant.8>
<9>Identifiers can be of any length.9>
<10>Variable names should not start with a number.10>
<11>As Python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class.11>
<12>True, False and None are capitalized while the others are in lower case.12>
<13>in is a keyword13>
<14>The else part of the code is not executed. if breaks the loop.14>
<15>The else part is executed when the condition in the while statement is false.15>
<16>We use the function append to
add an element to the list.16>
<17>Execute in the shell to verify.17>
<18>Execute in the shell to verify.18>
<19>Execute in the shell and verify.19>
<20>Execute in the shell to verify.20>
<21>Bitwise XOR gives 1 if either of the bits is 1 and 0 when both of the bits are 1.21>
<22>^ is the XOR operator. The binary form of 4 is 0100 and that of 12 is 1100. Therefore, 0100^1100 is 1000, which is equal to 8.22>
<23>The output of bin(10-2)= 0b1000 and that of bin(12^4) is ob1000. Hence the output of the above expression is: 0b10000b1000.23>
<24>The code shown above is used to swap the contents of two memory locations using bitwise X0R operator. Hence the output of the code shown above is: 20 10.24>
<25>Suppose we have an expression ~A. This is evaluated as: -A – 1. Therefore, the expression ~100 is evaluated as -100 – 1, which is equal to -101.25>
[/EXPLANATION]
Comments
Post a Comment