Python Week 1

Python Week 1


Graded Assignment


Multiple Choice Questions 🧠

1) What will be the output type of the expression 5 + 2?

int

float

str

bool

Invalid Expression (raises an error)

2) What will be the output type of the expression 5 + 2.0?

int

float

str

bool

Invalid Expression (raises an error)

3) What will be the output type of the expression '5' + "2"?

int

float

str

bool

Invalid Expression (raises an error)

4) What will be the output type of the expression 5 == 2?

int

float

str

bool

Invalid Expression (raises an error)

5) What will be the output type of the expression '5 > 2'?

int

float

str

bool

Invalid Expression (raises an error)

6) What will be the output type of the expression "5" > "2"?

int

float

str

bool

Invalid Expression (raises an error)

7) What will be the output type of the expression 'True' or 'False'?

int

float

str

bool

Invalid Expression (raises an error)

8) What will be the output type of the expression "555"[2]?

int

float

str

bool

Invalid Expression (raises an error)

9) What will be the output type of the expression 555[::2]?

int

float

str

bool

Invalid Expression (raises an error)

10) What will be the output type of the expression "555["2"]"?

int

float

str

bool

Invalid Expression (raises an error)

11) What will be the output type of the expression print('True')?

int

float

str

bool

NoneType

12) What will be the output type of the expression int("5.0") + float(2)?

int

float

str

bool

Raises an error

13) What will be the output type of the expression str(5) + str(2.0)?

int

float

str

bool

Raises an error

  1. Select the expression(s) that are equivalent to the given expression.
1
5 * 6 + 3 / 1

5 * (6 + (3 / 1))

(5 + 6) * 3 / 1

(5 * 6 + 3) / 1

(5 * 6) + (3 / 1)

15) Select the expression(s) that are equivalent to the given expression.

1
(1 + 2) * (3 + 4)

(1 + (2 * (3 + 4)))

(1 + 2) * 3 + 4

((1 + 2) * (3 + 4))

1 + (2 * 3) + 4

16) Select the expression(s) that are equivalent to the given expression.

1
a == b > c

(a == b) > c

a == (b > c)

(a == b) and (b > c)

(a == b) or (b > c)

17) Select the expression(s) that are equivalent to the given expression.

1
not (a or b) and c

not a or b and c

not (a or (b and c))

(not a) or (b and c)

(not (a or b)) and c

18) Select the expression(s) that are equivalent to the given expression.

1
not a or not b and c

(not a) or (not (b and c))

((not a) or (not b)) and c

(not a) or ((not b) and c)

not (a or (not b) and c)

19) How does the Python interpreter parenthesize the following expression?

1
not False or True and False

not (False or (True and False))

(not False) or (True and False)

not ((False or True) and False)

((not False) or True) and False

20) Select the correct statement(s) about print in python.

print is a built-in function.

In a python REPL/Notebook print("hi") will give same output as just “hi”.

print prints new line character at the end of the line.

print can be used to disply any data type.

21) Select the correct statement(s) about input in python.

input accepts atmost one argument.

Output type can be passed to input as input(type) to get output in the required type.

input can be only used in python scripts and not in REPL/Notebook.

Output type of input is always str

Common data for the next 3 questions 🔗

This set of questions is intended for you to practice python tutor and get used to it. Watch this tutorial on how to use python tutor before attempting this questions.

Consider the code present in this python tutor link.

Answer the following questions by using the python tutor interface. Consider the below code.


22) What is the value of a after executing line 3, using the input already given❓


23) What is the value of a after executing line 4, if input given changed to 4❓


24) What is the value of a after executing line 5, if the input is changed to 3❓

Common data for the next 3 questions 🔗

This set of questions is intended for you to practice python tutor and get used to it. Watch this tutorial on how to use python tutor before attempting this questions.

Consider the code present in this python tutor link.

Answer the following questions by using the python tutor interface.


25) What is the value of a after executing line 3, using the input already given?


26) What is the value of a after executing line 4, if input given changed to 14?


27) What is the value of a after executing line 5, if the input is changed to 23?

28) We need to write a program that accepts two names (strings) as input and prints True if the first name comes before the second in alphabetical order, and False otherwise.

Sample test cases:

InputOutput
sachin rohitFalse
saina sindhuTrue

For example, sachin comes after rohit, so the expected output is False. Select all correct implementations of this program.

1
2
3
name1 = input()
name2 = input()
print(name1 < name2)
1
2
3
name1 = input()
name2 = input()
print(name1 > name2)
1
print(input() < input())
1
print(input() > input())
1
2
3
4
name1 = input()
name2 = input()
result = name1 < name2
print(result)
1
2
3
4
name1 = input()
name2 = input()
result = name1 > name2
print(result)

29) What is the type of the following expression?

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

str

bool

True

False