Quiz 2
Registry Synced

May 2026 - Python - Week 2 - Week 2 - Graded Assignment 2

2598 words
13 min read

Week 2 - Graded Assignment 2

Course: May 2026 - Python
Week 2 - Graded Assignment 2 WEEK 2 Due Jul 01, 2026 11:59 PM IST Overdue

Introduction

Week 2 - Graded Assignment 2Week 2
1st Jul

Week 2 - Graded Assignment 2

Week 2
Due Jul 01, 202611:59 PM ISTOverdue

Question 1 / 35

2 marks
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
Try playing around in this python tutor link for answering the questions.
What is the total number of objects that were referenced by the variables in the given code during the execution?
Your Answer: (Not answered)

Question 2 / 35

2 marks
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: (Not answered)

Question 3 / 35

2 marks
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: (Not answered)

Question 4 / 35

2 marks
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.
Answer is Correct Score: 2 / 2
Options:
  • A. b ✅
  • B. c
  • C. d ✅
  • D. e
  • E. f

Question 5 / 35

2 marks
Assume s is a str, if the output of print(s) is A slash / and a backslash , then select the possible the value(s) of s.
Answer is Correct Score: 2 / 2
Options:
  • A. "A slash / and a backslash \" ✅
  • B. 'A slash / and a backslash \' ✅
  • C. 'A slash / and a backslash '
  • D. "A slash / and a backslash "

Question 6 / 35

3 marks
Consider the given code.
s = ''' name = "XXX" roll = NNN '''
Select the equivalent way(s) of defining s.
Answer is Partially Correct Score: 2.4 / 3
Options:
  • A. s = '\nname = "XXX"\nroll = NNN\n' ✅
  • B. s = 'name = "XXX"\nroll = NNN'
  • C. s = """ name = "XXX" roll = NNN """
  • D. s = """ name = "XXX" roll = NNN """ ✅
  • E. s = ( "\n", "name = "XXX"\n", "roll = NNN\n", )
  • F. s = ( "\n" "name = "XXX"\n" "roll = NNN\n" ) ✅
  • G. s = ( "\n"
    • "name = "XXX"\n"
    • "roll = NNN\n" ) ✅

Question 7 / 35

2 marks
Select the string(s) that are equal to "000500".
Answer is Correct Score: 2 / 2
Options:
  • A. f"{500:06}" ✅
  • B. f"{500:03}"
  • C. "0"*3+500
  • D. 0*3+"500"
  • E. "0"*3+"500" ✅

Question 8 / 35

2 marks
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``.
Answer is Correct Score: 2 / 2
Options:
  • A. s = r"{n_apples} apples and {n_bananas} bananas."
  • B. s = f'{n_apples} apples and {n_bananas} bananas.' ✅
  • C. s = f"{n_apples} apples and {n_bananas} bananas." ✅
  • D. s = n_apples+" apples and "+n_bananas+" bananas."
  • E. s = str(n_apples)+" apples and "+str(n_bananas)+" bananas." ✅
  • F. s = str(n_apples)+"apples and"+str(n_bananas)+"bananas."

Question 9 / 35

2 marks
Consider the below code block.
n_apples = 5 apple_price = 1.75 s = ... print(s)
If the output of the code is 5 kgs of apple cost ₹ 08.75, select the possible expression(s) that can be used for `s``.
Answer is Correct Score: 2 / 2
Options:
  • A. s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price:05.2f}" ✅
  • B. s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price:02.2f}"
  • C. s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price}"
  • D. s = f"{n_apples} kgs of apple cost ₹ {n_apples*apple_price:.2f}"
  • E. s = n_apples+" kgs of apple cost ₹ "+n_apples*apple_price
  • F. s = str(n_apples)+" kgs of apple cost ₹ 0"+str(n_apples*apple_price) ✅
  • G. s = str(n_apples)+" kgs of apple cost ₹ "+str(n_apples*apple_price)

Question 10 / 35

2 marks
Consider the below code block.
12
plaintext
a,b = "56"
s = f'{a*3:9}|{b*5:^9}|{a*7:>9}'
What is the value of the variable s? Enter the answer as a single quoted string.
python
a,b = "56"
s = f'{a*3:9}|{b*5:^9}|{a*7:>9}'
python
a,b = "56"
s = f'{a*3:9}|{b*5:^9}|{a*7:>9}'
Your Answer: (Not answered)

Question 11 / 35

1 mark
Assume s is a str variable. What is the type of the expression print(s.upper().split("-")))?
Answer is Wrong Score: 0 / 1
Options:
  • A. int
  • B. str
  • C. float
  • D. list ❌ (your answer)
  • E. bool
  • F. NoneType
  • G. Raises Error

Question 12 / 35

1 mark
Assume s is a str variable. What is the type of the expression s[:3].upper().split("-")?
Answer is Correct Score: 1 / 1
Options:
  • A. int
  • B. str
  • C. float
  • D. list ✅
  • E. bool
  • F. Raises Error

Question 13 / 35

1 mark
Assume s is a str variable. What is the type of the expression s.islower()?
Answer is Correct Score: 1 / 1
Options:
  • A. int
  • B. str
  • C. float
  • D. list
  • E. bool ✅
  • F. NoneType
  • G. Raises Error

Question 14 / 35

1 mark
Assume s is a str variable. What is the type of the expression s.startswith("hello")?
Answer is Correct Score: 1 / 1
Options:
  • A. int
  • B. str
  • C. float
  • D. list
  • E. bool ✅
  • F. NoneType
  • G. Raises Error

Question 15 / 35

1 mark
Assume s is a str variable. What is the type of the expression list(s)?
Answer is Wrong Score: 0 / 1
Options:
  • A. int
  • B. str
  • C. float
  • D. list ❌ (your answer)
  • E. bool
  • F. NoneType
  • G. Raises Error

Question 16 / 35

1 mark
Assume s is a str variable. What is the type of the expression s.lower().alpha()?
Answer is Correct Score: 1 / 1
Options:
  • A. int
  • B. str
  • C. float
  • D. list
  • E. bool
  • F. Raises error ✅

Question 17 / 35

1 mark
Assume s is a str variable. What is the type of the expression s.index('hi').isalpha()?
Answer is Correct Score: 1 / 1
Options:
  • A. int
  • B. str
  • C. float
  • D. list
  • E. bool
  • F. Raises error ✅

Question 18 / 35

1 mark
Assume s is a str variable. What is the type of the expression s.join(s[0])?
Answer is Correct Score: 1 / 1
Options:
  • A. int
  • B. str ✅
  • C. float
  • D. list
  • E. bool
  • F. Raises Error

Question 19 / 35

1 mark
What is the value of the expression bool('True')?
Answer is Correct Score: 1 / 1
Options:
  • A. True ✅
  • B. False
  • C. Raises Error

Question 20 / 35

1 mark
What is the value of the expression bool(-1)?
Answer is Correct Score: 1 / 1
Options:
  • A. True ✅
  • B. False
  • C. Raises Error

Question 21 / 35

1 mark
What is the value of the expression bool(0.0)?
Answer is Correct Score: 1 / 1
Options:
  • A. True
  • B. False ✅
  • C. Raises Error

Question 22 / 35

1 mark
What is the value of the expression bool('0.0')?
Answer is Correct Score: 1 / 1
Options:
  • A. True ✅
  • B. False
  • C. Raises Error

Question 23 / 35

1 mark
What is the value of the expression 0 or "2" and 4?
Answer is Correct Score: 1 / 1
Options:
  • A. True
  • B. False
  • C. "2"
  • D. 0
  • E. 4 ✅
  • F. Raises Error

Question 24 / 35

3 marks
Consider the below code
if a: print('a') elif b: print('b') elif c: print('c')
Select the possible output(s) of the given code, assuming any possible values for a, b and c.
Answer is Correct Score: 3 / 3
Options:
  • A. a ✅
  • B. b ✅
  • C. a b
  • D. a c
  • E. c ✅

Question 25 / 35

3 marks
Consider the below code
if a: print('a') if b: print('b') elif c: print('c')
Select the possible output(s) of the given code, assuming any possible values for a, b and c.
Answer is Wrong Score: 0 / 3
Options:
  • A. a ✅
  • B. b ✅
  • C. a b ✅
  • D. a c ✅
  • E. b c ❌ (your answer)

Question 26 / 35

3 marks
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.
Answer is Correct Score: 3 / 3
Options:
  • A. a ✅
  • B. b
  • C. c
  • D. b a ✅
  • E. b c
  • F. b c a ✅

Question 27 / 35

3 marks
Consider the given code.
if a: if b: print('ab') if c: print('ac')
Select the code block(s) that is/are equivalent to the above code.
Answer is Correct Score: 3 / 3
Options:
  • A. if a or b: print('ab') if a or c: print('ac')
  • B. if not (not a or not b): print('ab') if not (not a or not c): print('ac') ✅
  • C. if a and b: print('ab') if a and c: print('ac') ✅
  • D. if a and b: print('ab') elif c: print('ac')
  • E. if a: if b: print('ab') elif c: print('ac')
  • F. if a: if c: print('ac') if b: print('ab')
  • G. if b: if a: print('ab') if c: if a: print('ac') ✅

Question 28 / 35

2 marks
Select all the code snippet(s) that execute without any error.
Answer is Correct Score: 2 / 2
Options:
  • A. from math import sin, cos, sqrt ✅
  • B. import pi from math
  • C. from math import pi ✅
  • D. from math import pi as math_pi ✅

Question 29 / 35

3 marks
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
Answer is Partially Correct Score: 0.75 / 3
Options:
  • A. 1,3,26,26,0
  • B. 1,3,25,26,0 ✅
  • C. 1,3,25,25,0
  • D. 1,3,26,0,0
  • E. 1,3,25,0,0

Question 30 / 35

3 marks
A three digit number is called a sandwich number if the sum of its first and last digit is equal to its middle digit. Accept a three digit number as input and print sandwich if the number is a sandwich number. Print plain if the number is not a sandwich number. Select the correct implementation of the code that achieves this. Sample test cases follow:
Input Output
143 sandwich
118 plain
Answer is Correct Score: 3 / 3
Options:
  • A. num = int(input()) first, middle, last = num[0], num[1], num[2] if first + last == middle: print('sandwich') else: print('plain')
  • B. num = input() first, middle, last = num[0], num[1], num[2] if first + last == middle: print('sandwich') else: print('plain')
  • C. num = input() first, middle, last = int(num[0]), int(num[1]), int(num[2]) if first + last == middle: print('sandwich') else: print('plain') ✅
  • D. num = int(input()) first, middle, last = int(num[0]), int(num[1]), int(num[2]) if first + last == middle: print('sandwich') else: print('plain')

Question 31 / 35

3 marks
Chose the correct matching option for operator and related function in string .
Operator Function related to string
A. Replicates same string multiple times
B. Membership check
  1. [] C. Escape character
  2. [:] D. Concatenates two string
  3. in E. Range slice

  4. F. Character of the string using indexing
Chose the correct option for given code.
Answer is Correct Score: 3 / 3
Options:
  • A. 1-D, 2-A, 3-F, 4-E, 5-B, 6-C ✅
  • B. 1-D, 2-A, 3-F, 4-E, 5-C, 6-B
  • C. 1-D, 2-A, 3-E, 4-F, 5-B, 6-C
  • D. 1-A, 2-D, 3-E, 4-F, 5-B, 6-C

Question 32 / 35

2 marks
Consider the below code blocks.
Code-1
if a: if b: print('OK') if c: print('OK')
Code-2
if a and b or c: print('OK')
Choose the correct statements. It is a Multiple Select Question (MSQ).
Answer is Correct Score: 2 / 2
Options:
  • A. Code-1: OK will be printed once if either of a or b is True given that c is False
  • B. Code-2: OK will be printed once if either of a or b is True given that c is False
  • C. Code-1: OK will be printed twice only if all a, b and c are True ✅
  • D. Code-2: OK will be printed only if all a, b and c are True
  • E. Code-2: OK will be printed if c is True ✅
  • F. Code-1 and Code-2 will give same result for same values of a, b and c

Question 33 / 35

3 marks
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.
Answer is Partially Correct Score: 2.25 / 3
Options:
  • A. (a) Code-1: Always accepts two inputs ✅
  • B. (b) Code-2: Always accepts two inputs
  • C. (c) Code-1: If the first input is negative then program completes without printing anything ✅
  • D. (d) Code-2: If the first input is negative then program completes without printing anything
  • E. (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 / 35

1 mark
How many comparisons are done for the following input in Code-1?
-1 1
Your Answer: (Not answered)

Question 35 / 35

1 mark
How many comparisons are done for the following input in Code-2?
1 1
Your Answer: (Not answered)

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.