Week-1 Python Graded Assignment - IITM BS Degree

Week-1, Graded

Week-1, Graded

This document has 9 questions.

Question-1

Statement

What is the type of the following expression?

1 + 4 / 2

Options

(a) int

(b) float

(c) str

(d) bool

Answer

(b)

Hint

The division operation always results in a float value, irrespective of the type of either operand. As a follow-up, execute the following statements in the interpreter to get a better idea of the difference between the division operator (/) and the floor-division operator (//):

print(4 / 2)
print(4 // 2)

Question-2

Statement

What is the type of the following expression?

(1 > 0) and (-1 < 0) and (1 == 1)

Options

(a) str

(b) bool

(c) True

(d) False

Answer

(b)

Hint

Each comparison operation returns a Boolean value. These values are tied together by logical operators. Hence, the final outcome is a Boolean value.

Question-3

Statement

Convert the following mathematical statement into a Python expression.

10^3 + 9^3 = 12^3 + 1^3 = 1729

Options

(a)

(10^3) + (9^3) == (12^3) + (1^3) == 1729

(b)

(10 ** 3) + (9 ** 3) = (12 ** 3) + (1 ** 3) = 1729

(c)

(10 power 3) + (9 power 3) == (12 power 3) + (1 power 3) == 1729

(d)

(10 ** 3) + (9 ** 3) == (12 ** 3) + (1 ** 3) == 1729

Answer

(d)

Hint

** is the exponentiation operator. = is the assignment operator and should not be confused with == which is the equality operator.

Question-4

Statement

E_1 and E_2 are Boolean values. Consider the following expression.

E_3 = not (E_1 or E_2)
E_4 = (not E_1) and (not E_2)
print(E_3 == E_4)

What can you say about the value printed by the code given above?

Options

(a) It is True if and only if both E_1 and E_2 have the same value.

(b) It is False if and only if both E_1 and E_2 have the same value.

(c) It is always True.

(d) It is always False.

Answer

(c)

Hint

The idea here is to try out all possible combinations of values for the pair of variables (E_1, E_2). These combinations are:

E_1E_2
TrueTrue
TrueFalse
FalseTrue
FalseFalse

For those interested in knowing more about the expression, check out De Morgan's law.

Question-5

Statement

E is a boolean variable. Consider the following sequence of expressions:

not E
not not E
not not not E
not not not not E
.
.
.

This pattern keeps repeating for a thousand lines. If line number 500 evaluates to False, what is the value of E?

Options

(a) True

(b) False

(c) Cannot be determined

Answer

(b)

Hint

Two negatives make a positive. You should be able to figure out the explanation from here.

Common Data for Questions 6, 7

Statement

Common Data for questions (6) and (7)

Consider the following string:

word = '138412345678901938'

For what values of a and b does the following expression evaluate to True? Assume that both a and b are positive integers.

word[a : b] == '123456789'

Hint

Slice the string in such a way that you get the required substring.

Question-6

Statement

Enter the value of a. (NAT)

Answer

4

Question-7

Statement

Enter the value of b.

Answer

13

Post a Comment (0)
Previous Post Next Post