CSC201_OBJ_Questions.txt

[MAX]25[/MAX]

[QUESTIONS]

<1>What is the output of the following expression:
print(4.00/(2.0+2.0))

<2>Consider the expression given below.
The value of X is:
X = 2+9*((3*12)-8)/10

<3>Which of the following expressions involves coercion when evaluated in Python?

<4>What is the value of the following expression:
24//6%3, 24//4//2

<5>What is the value of the expression:
float(4+int(2.39)%2)

<6>Which of the following expressions results in an error?

<7>What is the value of the expression:
4+2**5//10

<8>Is Python case sensitive when dealing with identifiers?

<9>What is the maximum possible length of an identifier?

<10>Which of the following is an invalid variable?

<11>Why are local variable names beginning with an underscore discouraged?

<12>All keywords in Python are in

<13>Which of the following cannot be a variable?

<14>What is the output of the following?
i = 0
while i < 5: print(i)
i += 1
if i == 3:
break
else: print(0)


<15>What is the output of the following?
i = 0
while i < 3: print(i)
i += 1
else: print(0)


<16>To add a new element to a list we use which command?

<17>To insert 5 to the third position in list1, we use which command ?

<18>To remove string “hello” from list1, we use which command?

<19>Suppose list1 is [1, 3, 2], What is list1 * 2 ?

<20>Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?

<21>Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.

<22>The result of the expression shown below is:
4^12

<23>What is the value of this expression:
bin(10-2)+bin(12^4)

<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)

<25>What is the value of the expression:
~100

[/QUESTIONS]

[OPTIONS]

<1>Error
1.0
1.00
1

<2>30.0
30.8
28.4
27.2

<3>4.7–1.5
7.9*6.3
1.7%2
3.4+4.6

<4>(1,3)
(0,3)
(1,0)
(3,1)

<5>5.0
5
4.0
4

<6>float(‘10’)
int(‘10’)
float(’10.8’)
int(’10.8’)

<7>3
7
77
0

<8>yes
no
machine dependent
none of the above

<9>31 characters
63 characters
79 characters
none of the above

<10>my_string_1
1st_string
foo
_

<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 execution

<12>lower case
UPPER CASE
Capitalized
None of the above

<13>__init__
in
it
on

<14>0 1 2 0
0 1 2
error
none of the above

<15>0 1 2 3 0
0 1 2 0
0 1 2
error

<16>list1.add(5)
list1.append(5)
list1.addLast(5)
list1.addEnd(5)

<17>list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)

<18>list1.remove(“hello”)
list1.remove(hello)
list1.removeAll(“hello”)
list1.removeOne(“hello”)

<19>[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]

<20>0
4
1
2

<21>OR
AND
XOR
NOT

<22>2
4
8
12

<23>0b10000
0b10001000
0b1000b1000
0b10000b1000

<24>10 20
10 10
20 10
20 20

<25>101
-101
100
-100

[/OPTIONS]

[ANSWERS]

<1>1.0

<2>27.2

<3>1.7%2

<4>(1,3)

<5>4.0

<6>int(’10.8’)

<7>7

<8>yes

<9>none of the above

<10>1st_string

<11>they areused to indicate a private variables of a class

<12>None of the above

<13>in

<14>0 1 2

<15>0 1 2 0

<16>list1.append(5)

<17>list1.insert(3, 5)

<18>list1.remove(“hello”)

<19>[1, 3, 2, 1, 3, 2]

<20>2

<21>XOR

<22>8

<23>0b10000b1000

<24>20 10

<25>-101

[/ANSWERS]

[EXPLANATION]
<1>The result of the expression shown above is 1.0 because print rounds off digits.

<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.

<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).

<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.

<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.

<6>All of the above examples show explicit conversion. However the expression int(’10.8’) results in an error.

<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.

<8>Case is always significant.

<9>Identifiers can be of any length.

<10>Variable names should not start with a number.

<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.

<12>True, False and None are capitalized while the others are in lower case.

<13>in is a keyword

<14>The else part of the code is not executed. if breaks the loop.

<15>The else part is executed when the condition in the while statement is false.

<16>We use the function append to
add an element to the list.

<17>Execute in the shell to verify.

<18>Execute in the shell to verify.

<19>Execute in the shell and verify.

<20>Execute in the shell to verify.

<21>Bitwise XOR gives 1 if either of the bits is 1 and 0 when both of the bits are 1.

<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.

<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.

<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.

<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.

[/EXPLANATION]

Comments

Popular posts from this blog

AcronymsandtheirMeanings_German_Questions.txt

ECN201_Theory_Questions.txt

CurrentAffairs_German_Questions.txt