Registry Synced

Jan 2026 - Python - Week 2 - Graded Assignment 2

4400 words
22 min read

Week 2 - Graded Assignment 2

Course: Jan 2026 - Python
Week 2 - Graded Assignment 2
Last Submitted: You have last submitted on: 2026-02-25, 16:51 IST

Question 1

Common data for the next 4 questions
Consider the below code.
python
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)
Status: Yes, the answer is correct. Score: Score: 2
Feedback/Explanation: (Type: String) 3
Accepted Answers:
(Type: String) 3

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: 2
Status: Yes, the answer is correct. Score: Score: 2
Feedback/Explanation: (Type: String) 2
Accepted Answers:
(Type: String) 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: 4
Status: Yes, the answer is correct. Score: Score: 2
Feedback/Explanation: (Type: String) 4
Accepted Answers:
(Type: String) 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. Score: Score: 2
Feedback/Explanation: b
d
Accepted Answers:
b
d

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 \\\\"""
Feedback/Explanation: 'Single backslash \\\\ and double backslash \\\\\\\\'
Accepted Answers:
'Single backslash \\\\ and double backslash \\\\\\\\'

Question 6

Assume s is a str, if the output of print(s) is given below.
plain
apple
banana
cherry
Note: There is a newline at the end.
Select the possible the value(s) of s.
  • ```python s = "apple\nbanana\ncheryy\n"
  • ```python s = """apple banana cherry """
  • ```python s = """ apple banana cherry"""
  • ```python s = ( 'apple\n', 'banana\n', 'cherry\n', )
  • ```python s = ( 'apple\n' 'banana\n' 'cherry\n' )
  • ```python s = 'apple\n'"banana\n"'cherry\n'
  • ```python s = 'apple\n'+"banana\n"+'cherry\n'
  • ```python apple = 'apple\n' cherry = 'cherry\n' s = apple+"banana\n"+cherry
  • ```python apple = 'apple\n' cherry = 'cherry\n' s = apple"banana\n"cherry
Feedback/Explanation:
python
s = "apple\nbanana\ncheryy\n"
python
s = """apple
banana
cherry
"""
python
s = (
  'apple\n'
  'banana\n'
  'cherry\n'
)
python
s = 'apple\n'"banana\n"'cherry\n'
python
s = 'apple\n'+"banana\n"+'cherry\n'
python
apple  = 'apple\n'
cherry  = 'cherry\n'
s = apple+"banana\n"+cherry
Accepted Answers:
python
s = "apple\nbanana\ncheryy\n"
python
s = """apple
banana
cherry
"""
python
s = (
  'apple\n'
  'banana\n'
  'cherry\n'
)
python
s = 'apple\n'"banana\n"'cherry\n'
python
s = 'apple\n'+"banana\n"+'cherry\n'
python
apple  = 'apple\n'
cherry  = 'cherry\n'
s = apple+"banana\n"+cherry

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. Score: Score: 2
Feedback/Explanation: f"{500:06}"
"0"*3+"500"
Accepted Answers:
f"{500:06}"
"0"*3+"500"

Question 8

Consider the below code block.
python
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."
Feedback/Explanation: 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."
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."

Question 9

Consider the below code block.
python
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. Score: Score: 2
Feedback/Explanation: 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"
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"

Question 10

Consider the below code block.
python
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: (Not answered)
Feedback/Explanation: (Type: String) '55 | 6 | 555'
Accepted Answers:
(Type: String) '55 | 6 | 555'

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. Score: Score: 1
Feedback/Explanation: bool
Accepted Answers:
bool

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. Score: Score: 1
Feedback/Explanation: Raises Error
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. Score: Score: 1
Feedback/Explanation: bool
Accepted Answers:
bool

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. Score: Score: 1
Feedback/Explanation: Raises error
Accepted Answers:
Raises error

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. Score: Score: 1
Feedback/Explanation: Raises error
Accepted Answers:
Raises error

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. Score: Score: 1
Feedback/Explanation: Raises error
Accepted Answers:
Raises error

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. Score: Score: 1
Feedback/Explanation: str
Accepted Answers:
str

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. Score: Score: 1
Feedback/Explanation: str
Accepted Answers:
str

Question 19

What is the value stored in the variable x?
python
x = bool(input())
Input
plain
False
  • False
  • True
  • Value Error
  • 'False'
Status: Yes, the answer is correct. Score: Score: 2
Feedback: As you know, the function input() reads the value passed by the user as a string. Here, the value entered by user is a boolean literal False. The input()function returns it as a string literal 'False'. It is then transformed by the function bool() to the boolean literal False and is stored in the variable x.
The given code can be interpreted as:
x = bool('False')
Below table shows how values are transformed by bool() function:
<table style="box-sizing: border-box;font-size: 16px;margin: 1em 0;border-collapse: collapse;width: fit-content;max-width: 100%;overflow-x: auto;display: block;font-variant-numeric: lining-nums tabular-nums;" border="1"><thead style="box-sizing: border-box;font-size: 16px;"><tr style="box-sizing: border-box;font-size: 16px;"><th style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;">Type</th><th style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;">Values</th><th style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;">Boolean Conversion</th></tr></thead><tbody style="box-sizing: border-box;font-size: 16px;margin-top: 0.5em;border-top: thin solid #000;border-bottom: thin solid #000;"><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">int</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">0</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">False</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">int</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">1</span>,<span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">2</span>,<span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">3</span>,..., <span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">-1</span>, <span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">-2</span>,..., , <span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">10**2</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">True</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">float</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">0.0</span>, <span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">-0.0</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">False</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">float</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">0.00001</span>, <span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">2.718</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">True</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">str</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">""</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">False</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">str</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">" "</span>, <span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">"a"</span>, <span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">"hello"</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">True</span></td></tr></tbody></table>
Accepted Answers:
True

Question 20

What is the value of the expression bool('True')?
  • True
  • False
  • Raises Error
Status: Yes, the answer is correct. Score: Score: 1
Feedback/Explanation: True
Accepted Answers:
True

Question 21

What is the value of the expression bool(False)?
  • True
  • False
  • Raises Error
Status: Yes, the answer is correct. Score: Score: 1
Feedback/Explanation: False
Accepted Answers:
False

Question 22

What is the value of the expression bool(-1)?
  • True
  • False
  • Raises Error
Status: Yes, the answer is correct. Score: Score: 1
Feedback/Explanation: True
Accepted Answers:
True

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. Score: Score: 1
Feedback/Explanation: "2"
Accepted Answers:
"2"

Question 24

Consider the below code
python
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.
  • ```plain-text a
  • ```plain-text b
  • ```plain-text a b
  • ```plain-text b a
  • ```plain-text c b
  • ```plain-text c b a
Feedback/Explanation:
plain
a
plain
b
a
plain
c
b
a
Accepted Answers:
plain
a
plain
b
a
plain
c
b
a

Question 25

Consider the below code
python
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.
  • ```plain-text a
  • ```plain-text b
  • ```plain-text b a
  • ```plain-text c b
  • ```plain-text c b a
Feedback/Explanation:
plain
a
plain
b
Accepted Answers:
plain
a
plain
b

Question 26

Consider the below code
python
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.
  • ```plain-text a
  • ```plain-text b
  • ```plain-text c
  • ```plain-text b a
  • ```plain-text b c
  • ```plain-text b c a
Status: Yes, the answer is correct. Score: Score: 3
Feedback/Explanation:
plain
a
plain
b
a
plain
b
c
a
Accepted Answers:
plain
a
plain
b
a
plain
b
c
a

Question 27

Consider the given code.
python
if a:
  if b:
    if c:
      print('abc')
Select the code block(s) that is/are equivalent to the above code.
  • ```python if a or b or c: print('abc')
  • ```python if a and b and c: print('abc')
  • ```python if a: if b and c: print('abc')
  • ```python if c: if b and a: print('abc')
  • ```python if not c: pass else: if b and a: print('abc')
  • ```python if not c: pass else: if not b or not a: print('abc')
Status: Yes, the answer is correct. Score: Score: 3
Feedback/Explanation:
python
if a and b and c:
    print('abc')
python
if a:
    if b and c:
        print('abc')
python
if c:
    if b and a:
        print('abc')
python
if not c:
    pass
else:
    if b and a:
        print('abc')
Accepted Answers:
python
if a and b and c:
    print('abc')
python
if a:
    if b and c:
        print('abc')
python
if c:
    if b and a:
        print('abc')
python
if not c:
    pass
else:
    if b and a:
        print('abc')

Question 28

Select all the code snippet(s) that execute without any error.
  • ```python from math import *
  • ```python import math as m m.sin, m.cos
  • ```python import pi from math
  • ```python import math math.sin, math.cos
Status: Yes, the answer is correct. Score: Score: 2
Feedback/Explanation:
python
from math import *
python
import math as m
m.sin, m.cos
python
import math
math.sin, math.cos
Accepted Answers:
python
from math import *
python
import math as m
m.sin, m.cos
python
import math
math.sin, math.cos

Question 29

Consider the following snippet of code:
python
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)
  • ```plain-text (a{b[c]})
  • ```plain-text abcd
  • ```plain-text )(][}{
  • ```plain-text a(db]
Status: Yes, the answer is correct. Score: Score: 2
Feedback: The idea being expressed should be quite clear: for every type of parenthesis, are there an equal number opening and closing parentheses? The important point to note here is word.count(char) will return zero if char is not found in word. So, option (b) is also correct!
Accepted Answers:
plain
(a{b[c]})
plain
abcd
plain
)(][}{

Question 30

Consider the below code snippet.
python
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 ?
plain
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
Feedback: s[start​ : end : step]
start is start index.
end is last index+1(because end is not inclusive ).
step define interval of indexing in range (start , start+step , start+step+step,......end-1).
For traverse string left to right:-
  • If start, end and step is not defined in slicing then by default start will be first index of string, end will be one more then from last index of element and step will be 1.
  • If we are visiting elements from left to right ,we must remember that the start index must be at the left side from the end index and the step value should be positive.
For traverse string right to left:-
  • step value must be mention and it should be negative
  • If we are visiting elements from right to left ,we must remember that the start index must be at the right side from the end index and the step value should be negative.
  • If start and end index is not defined and step value is negative so by default start index will be the last index of string and end index will be one less then from first index of string.
We can see that in the output, characters are printed in reverse order from last character to first character with an interval of 3. So all possible combinations given in the answer will print the same output zwtqnkheb 5 times.
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.
python
a, b, c, d = input()
Input
plain
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: (Not answered)
Status: Yes, the answer is correct. Score: Score: 3
Feedback/Explanation: (Type: String) 1,2,3,4
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.
plain
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.
plain
1234
  • ```plain-text 1234 1234 1234 1234
  • ```plain-text 1 2 3 4
  • ```plain-text 1 1 1 1
  • ```plain-text 4 4 4 4
Status: Yes, the answer is correct. Score: Score: 3
Feedback:
<table style="box-sizing: border-box;font-size: 16px;margin: 1em 0;border-collapse: collapse;width: fit-content;max-width: 100%;overflow-x: auto;display: block;font-variant-numeric: lining-nums tabular-nums;" border="1"><thead style="box-sizing: border-box;font-size: 16px;"><tr style="box-sizing: border-box;font-size: 16px;"><th style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;">Variable</th><th style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;">Value</th></tr></thead><tbody style="box-sizing: border-box;font-size: 16px;margin-top: 0.5em;border-top: thin solid #000;border-bottom: thin solid #000;"><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">a</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">'1'</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">b</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">'2'</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">c</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">'3'</span></td></tr><tr style="box-sizing: border-box;font-size: 16px;"><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">d</span></td><td style="box-sizing: border-box;font-size: 16px;border: thin solid #000;padding: 0.5em 0.5em 0.25em 0.5em;"><span style="box-sizing: border-box;font-size: 85%;font-family: monospace;padding: 1px 5.5px 3px 5.5px;background-color: rgba(0, 0, 0, 0.07);border-radius: 5px">'4'</span></td></tr></tbody></table>
The statement accepts a string of length 4 and assigns each character to variables a, b, c and d in the order it is entered. If the number of characters in the entered string is not equal to 4 , a ValueError is thrown by the interpreter.
Accepted Answers:
plain
1
2
3
4

Question 33

Common data for the next 3 questions
Consider the below code blocks.

Code-1

python
a = int(input())
b = int(input())
if a > 0:
    if b < 0:
        print('OK')

Code-2

python
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
Feedback: Option (a) is correct. The interpreter executed statements sequentially in a program. In Code-1 block, line-1 accepts user input and store in a variable a. On line-2, it accepts another input from console and stores in variable b. Therefore, it always accepts two inputs.
Option (c) is correct. In Code-1, if the first input number a is negative, the condition if a > 0: is evaluated False, the control doesn't enter inside the body of this if block and therefore subsequent statement if b > 0: is skipped.
Option (d) is correct. If the number entered for the first input() call is less than 0, the condition if int(input()) > 0 and int(input()) < 0: evaluates False. Thus, neither second input() is executed, nor the print('OK') statements inside the body of this if block.
Option (e) is correct. One can change the value of a variable anywhere in the program. Here is an example to reassign 1 to the variable a on line-2.
a = int(input()) a = 1 b = int(input()) if a > 0: if b < 0: print('OK')
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?
plain
-1
1
Your Answer: (Not answered)
Status: Yes, the answer is correct. Score: Score: 1
Feedback/Explanation: (Type: String) 1
Accepted Answers:
(Type: String) 1

Question 35

How many comparisons are done for the following input in Code-2?
plain
1
1
Your Answer: (Not answered)
Status: Yes, the answer is correct. Score: Score: 1
Feedback/Explanation: (Type: String) 2
Accepted Answers:
(Type: String) 2

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