Neural Sync Active
Week 2 - Graded Assignment 2
Registry Synced
Week 2 - Graded Assignment 2
2802 words
14 min read
Course: Jan 2026 - Python
Topic: Python Object Aliasing and Referencing | Marks: 4
Question 1
Common data for the next 4 questions
Consider the below code.
a = 5 b = a c = "hello" d = c[:3] b,d = c,b b,e = d,b d,b = e,c f,d = d,e del e
What is the total number of objects that were referenced by the variables in the given code during the execution?
Your Answer:
3Status: Yes, the answer is correct.
Accepted Answers:
(Type: String) 3
Topic: Object Lifetimes after Deletion | Marks: 2
Question 2
What is the total number of objects that were referenced by the variables in the given code at the end of the execution?
Your Answer:
2Status: Yes, the answer is correct.
Accepted Answers:
(Type: String) 2
Topic: Reference Counting and Shared Objects | Marks: 2
Question 3
What is the total number of variables refering to the same object as variable b (including b) at the end of the execution of the given code?
Your Answer:
4Status: Yes, the answer is correct.
Accepted Answers:
(Type: String) 4
Topic: Tracking Identical References | Marks: 4
Question 4
Select the variable(s) that are refering to the same object as a at some point of time during the execution of the above code.
- b
- c
- d
- e
- f
Status: Yes, the answer is correct.
Accepted Answers:
b
d
Topic: String Escape Sequences (Backslashes) | Marks: 3
Question 5
Assume s is a str, if the output of print(s) is Single backslash \\ and double backslash \\\\, then select the possible the value(s) of s.
- 'Single backslash \\\\ and double backslash \\\\\\\\'
- 'Single backslash \\ and double backslash \\\\'
- 'Single backslash /\/\ and double backslash /\/\/\/\'
- '''Single backslash \\ and double backslash \\\\'''
- """Single backslash \\ and double backslash \\\\"""
Accepted Answers:
'Single backslash \\\\ and double backslash \\\\\\\\'
Topic: Multiline Strings and Newlines | Marks: 4
Question 6
Assume s is a str, if the output of print(s) is given below.
apple banana cherry
Note: There is a newline at the end.
Select the possible the value(s) of s.
- ```
s = "apple\nbanana\ncheryy\n" - ```
s = """apple
banana
cherry
""" - ```
s = """
apple
banana
cherry""" - ```
s = (
'apple\n',
'banana\n',
'cherry\n',
) - ```
s = (
'apple\n'
'banana\n'
'cherry\n'
) - ```
s = 'apple\n'"banana\n"'cherry\n' - ```
s = 'apple\n'+"banana\n"+'cherry\n' - ```
apple = 'apple\n'
cherry = 'cherry\n'
s = apple+"banana\n"+cherry - ```
apple = 'apple\n'
cherry = 'cherry\n'
s = apple"banana\n"cherry
Accepted Answers:
s = "apple\nbanana\ncheryy\n"
s = """apple banana cherry """
s = ( 'apple\n' 'banana\n' 'cherry\n' )
s = 'apple\n'"banana\n"'cherry\n'
s = 'apple\n'+"banana\n"+'cherry\n'
apple = 'apple\n' cherry = 'cherry\n' s = apple+"banana\n"+cherry
Topic: f-strings and Padding | Marks: 2
Question 7
Select the string(s) that are equal to "000500".
- f"{500:06}"
- f"{500:03}"
- "0"*3+500
- 0*3+"500"
- "0"*3+"500"
Status: Yes, the answer is correct.
Accepted Answers:
f"{500:06}"
"0"*3+"500"
Topic: String Formatting and raw-strings | Marks: 2
Question 8
Consider the below code block.
n_apples = 5 n_bananas = 7 s = ... print(s)
If the output of the code is 5 apples and 7 bananas., select the possible expression(s) that can be used for `s``.
- s = r"{n_apples} apples and {n_bananas} bananas."
- s = f'{n_apples} apples and {n_bananas} bananas.'
- s = f"{n_apples} apples and {n_bananas} bananas."
- s = n_apples+" apples and "+n_bananas+" bananas."
- s = str(n_apples)+" apples and "+str(n_bananas)+" bananas."
- s = str(n_apples)+"apples and"+str(n_bananas)+"bananas."
Accepted Answers:
s = f'{n_apples} apples and {n_bananas} bananas.'
s = f"{n_apples} apples and {n_bananas} bananas."
s = str(n_apples)+" apples and "+str(n_bananas)+" bananas."
Topic: Precision Formatting in f-strings | Marks: 2
Question 9
Consider the below code block.
n_apples = 5 apple_price = 5.7 s = ... print(s)
If the output of the code is 5 kgs of apple cost ₹ 28.50, select the possible expression(s) that can be used for `s``.
- s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price}"
- s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price:0.2f}"
- s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price:.2f}"
- s = n_apples+" kgs of apple cost ₹ "+n_apples*apple_price
- s = str(n_apples)+" kgs of apple cost ₹ "+str(n_apples*apple_price)
- s = str(n_apples)+" kgs of apple cost ₹ "+str(n_apples*apple_price)+"0"
Status: Yes, the answer is correct.
Accepted Answers:
s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price:0.2f}"
s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price:.2f}"
s = str(n_apples)+" kgs of apple cost ₹ "+str(n_apples*apple_price)+"0"
Topic: String Alignment in f-strings | Marks: 4
Question 10
Consider the below code block.
a,b = "56" s = f'{a*2:5}|{b:^5}|{a*3:>7}'
What is the value of the variable s? Enter the answer as a single quoted string.
Your Answer:
55Accepted Answers:
(Type: String) '55 | 6 | 555'
Topic: Chained String methods return types | Marks: 2
Question 11
Assume s is a str variable. What is the type of the expression s.lower().isalpha()?
- int
- str
- float
- list
- bool
- NoneType
Status: Yes, the answer is correct.
Accepted Answers:
bool
Topic: Missing Arguments (Method Signature) | Marks: 2
Question 12
Assume s is a str variable. What is the type of the expression s.startswith()?
- int
- str
- float
- list
- bool
- NoneType
- Raises Error
Status: Yes, the answer is correct.
Accepted Answers:
Raises Error
Question 13
Assume s is a str variable. What is the type of the expression s.lower().isalpha()?
- int
- str
- float
- list
- bool
- Raises error
Status: Yes, the answer is correct.
Accepted Answers:
bool
Topic: Non-existent Methods (AttributeError) | Marks: 2
Question 14
Assume s is a str variable. What is the type of the expression s.lowercase().isalpha()?
- int
- str
- float
- list
- bool
- Raises error
Status: Yes, the answer is correct.
Accepted Answers:
Raises error
Topic: Argument Type Validation | Marks: 2
Question 15
Assume s is a str variable. What is the type of the expression s.index(3)?
- int
- str
- float
- list
- bool
- Raises error
Status: Yes, the answer is correct.
Accepted Answers:
Raises error
Topic: Chained Attribute Access (Properties vs Methods) | Marks: 2
Question 16
Assume s is a str variable. What is the type of the expression s.title.strip()?
- int
- str
- float
- list
- bool
- Raises error
Status: Yes, the answer is correct.
Accepted Answers:
Raises error
Topic: String Sanitization Chain | Marks: 2
Question 17
Assume s is a str variable. What is the type of the expression s.title().strip("-")?
- int
- str
- float
- list
- bool
- Raises Error
Status: Yes, the answer is correct.
Accepted Answers:
str
Topic: Join Method Return Type | Marks: 2
Question 18
Assume s is a str variable. What is the type of the expression s.join([s[0],s[1],s[3]])?
- int
- str
- float
- list
- bool
- Raises Error
Status: Yes, the answer is correct.
Accepted Answers:
str
Topic: Boolean Truthiness of Inputs | Marks: 3
Question 19
What is the value stored in the variable x?
x = bool(input())
Input
False
- False
- True
- Value Error
- 'False'
Status: Yes, the answer is correct.
Accepted Answers:
True
Topic: Non-Empty String Truthiness | Marks: 2
Question 20
What is the value of the expression bool('True')?
- True
- False
- Raises Error
Status: Yes, the answer is correct.
Accepted Answers:
True
Topic: Literal Boolean Truthiness | Marks: 2
Question 21
What is the value of the expression bool(False)?
- True
- False
- Raises Error
Status: Yes, the answer is correct.
Accepted Answers:
False
Topic: Non-zero Integer Truthiness | Marks: 2
Question 22
What is the value of the expression bool(-1)?
- True
- False
- Raises Error
Status: Yes, the answer is correct.
Accepted Answers:
True
Topic: Boolean OR Short-circuiting | Marks: 3
Question 23
What is the value of the expression 0.0 or "2" or 4?
- True
- False
- "2"
- 0.0
- 4
- Raises Error
Status: Yes, the answer is correct.
Accepted Answers:
"2"
Topic: Nested If Structure | Marks: 4
Question 24
Consider the below code
if a: if b: if c: print('c') print('b') print('a')
Select the possible output(s) of the given code, assuming any possible values for a, b and c.
- ```
a - ```
b - ```
a
b - ```
b
a - ```
c
b - ```
c
b
a
Accepted Answers:
a
b a
c b a
Topic: If-Else Nesting Logic | Marks: 4
Question 25
Consider the below code
if a: if b: if c: print('c') else: print('b') else: print('a')
Select the possible output(s) of the given code, assuming any possible values for a, b and c.
- ```
a - ```
b - ```
b
a - ```
c
b - ```
c
b
a
Accepted Answers:
a
b
Question 26
Consider the below code
if a: if b: print('b') if c: print('c') print('a')
Select the possible output(s) of the given code, assuming any possible values for a, b and c.
- ```
a - ```
b - ```
c - ```
b
a - ```
b
c - ```
b
c
a
Status: Yes, the answer is correct.
Accepted Answers:
a
b a
b c a
Topic: Boolean Logic Equivalence | Marks: 4
Question 27
Consider the given code.
if a: if b: if c: print('abc')
Select the code block(s) that is/are equivalent to the above code.
- ```
if a or b or c:
print('abc') - ```
if a and b and c:
print('abc') - ```
if a:
if b and c:
print('abc') - ```
if c:
if b and a:
print('abc') - ```
if not c:
pass
else:
if b and a:
print('abc') - ```
if not c:
pass
else:
if not b or not a:
print('abc')
Status: Yes, the answer is correct.
Accepted Answers:
if a and b and c: print('abc')
if a: if b and c: print('abc')
if c: if b and a: print('abc')
if not c: pass else: if b and a: print('abc')
Question 28
Select all the code snippet(s) that execute without any error.
- ```
from math import * - ```
import math as m
m.sin, m.cos - ```
import pi from math - ```
import math
math.sin, math.cos
Status: Yes, the answer is correct.
Accepted Answers:
from math import *
import math as m m.sin, m.cos
import math math.sin, math.cos
Question 29
Consider the following snippet of code:
word = input() match = False if word.count('(') == word.count(')'): if word.count('[') == word.count(']'): if word.count('{') == word.count('}'): match = True if match: print('PERFECT!') else: print('IMPERFECT!')
Select all possible inputs for which this code prints PERFECT! as output. (MSQ)
- ```
(a{b[c]}) - ```
abcd - ```
)(][}{ - ```
a(db]
Status: Yes, the answer is correct.
Accepted Answers:
(a{b[c]})
abcd
)(][}{
Question 30
Consider the below code snippet.
s = "abcdefghijklmnopqrstuvwxyz" a = int(input()) b = int(input()) c = int(input()) d = int(input()) e = int(input()) print(s[-a:-len(s):-3]) print(s[::-b]) print(s[c:0:-3]) print(s[len(s):-d:-3]) print(s[:e:-3])
Select the user input combination(s) of a, b, c , d and e (where 0 <= a,b,c,d,e <= len(s) ) does the above code-snippet print following output ?
zwtqnkheb zwtqnkheb zwtqnkheb zwtqnkheb zwtqnkheb
- 1,3,26,26,0
- 1,3,25,26,0
- 1,3,25,25,0
- 1,3,26,0,0
- 1,3,25,0,0
Accepted Answers:
1,3,26,26,0
1,3,25,26,0
1,3,26,0,0
1,3,25,0,0
Question 31
Consider the below code block and input.
a, b, c, d = input()
Input
1234
What will be the value stored in the variables a, b, c and d? Give your answer separated by commas without any spaces in between the values. For example 9,7,1,0
Your Answer:
1,2,3,4Status: Yes, the answer is correct.
Accepted Answers:
(Type: String) 1,2,3,4
Question 32
Exploratory Problem: This problem is meant to encourage you to try certain things outside the lectures.
Consider the following snippet of code.
a, b, c, d = input() print(a) print(b) print(c) print(d)
What is the output of this code for the following input? Feel free to use the Python interpreter for exploratory questions.
1234
- ```
1234
1234
1234
1234 - ```
1
2
3
4 - ```
1
1
1
1 - ```
4
4
4
4
Status: Yes, the answer is correct.
Accepted Answers:
1 2 3 4
Question 33
Common data for the next 3 questions
Consider the below code blocks.
Code-1
a = int(input()) b = int(input()) if a > 0: if b < 0: print('OK')
Code-2
if int(input()) > 0 and int(input()) < 0: print('OK')
Choose the correct statement(s) from below regarding the code blocks.
- (a) Code-1: Always accepts two inputs
- (b) Code-2: Always accepts two inputs
- (c) Code-1: If the first input is negative then program completes without printing anything
- (d) Code-2: If the first input is negative then program completes without printing anything
- (e) Code-1: It is possible to change the value of a by introducing a new line of code before accepting the value of b
Accepted Answers:
(a) Code-1: Always accepts two inputs
(c) Code-1: If the first input is negative then program completes without printing anything
(d) Code-2: If the first input is negative then program completes without printing anything
(e) Code-1: It is possible to change the value of a by introducing a new line of code before accepting the value of b
Question 34
How many comparisons are done for the following input in Code-1?
-1 1
Your Answer:
1Status: Yes, the answer is correct.
Accepted Answers:
(Type: String) 1
Question 35
How many comparisons are done for the following input in Code-2?
1 1
Your Answer:
2Status: Yes, the answer is correct.
Accepted Answers:
(Type: String) 2
🧭 Navigation
- 📘 Textbook Notes: Week 2 Notes
- 📝 Assignment: Week 2 Assignment
- ⬅️ Previous Week: Week 1 Notes
- ➡️ Next Week: Week 3 Notes