Registry Synced

Week 1 Graded Assignment 1

2917 words
15 min read
Course: Jan 2026 - Python

Topic: Basic Integer Arithmetic | Marks: 2

Question 1

What will be the output type of the expression 5 + 2?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Identify Operands: Both operands are integers (55 and 22).
  2. Identify Operator: Addition (++) between two integers results in an integer in Python. ^python-w1-q1-strategy

Procedure

  • 55 is of type int.
  • 22 is of type int.
  • 5 + 2 evaluates to 77, which is an int.
Accepted Answers: int

Topic: Python Division Rules | Marks: 2

Question 2

What will be the output type of the expression 5 / 2?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Python Division Rule: In Python 3, the standard division operator (/) always returns a floating-point number, even if the division is exact (e.g., 4 / 2 is 2.0).

Procedure

  • 5/25 / 2 evaluates to 2.52.5.
  • 2.52.5 is of type float.
Rules: Standard division / always results in a float.
Accepted Answers: float

Topic: Float Promotion and Exponentiation | Marks: 2

Question 3

What will be the output type of the expression 5 ** 2.0?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Mixed Type Promotion: If any operand in an arithmetic operation is a float, the result is promoted to a float.
  2. Operator: Exponentiation (**).

Procedure

  • 55 is int, 2.02.0 is float.
  • 52.0=25.05^{2.0} = 25.0.
  • Type is float.
Accepted Answers: float

Topic: String Literals | Marks: 2

Question 4

What will be the output type of the expression "5 + 2"?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Literal Identification: Content enclosed in quotes ("..." or '...') is treated as a string literal.

Procedure

  • The expression is enclosed in double quotes.
  • No arithmetic is performed inside the string by the interpreter in this context.
  • Output is the string object "5 + 2".
Accepted Answers: str

Topic: Short-circuit Evaluation | Marks: 3

Question 5

What will be the output type of the expression 5 and 2 or "2"?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Short-circuiting: In Python, x and y returns xx if xx is falsy, otherwise it returns yy. x or y returns xx if xx is truthy, otherwise it returns yy.
  2. Truthiness: Non-zero integers are truthy.
  3. Precedence: and has higher precedence than or. ^short-circuit-logic

Procedure

  • 5 and 2: 55 is truthy, so it returns 22.
  • The expression becomes 2 or "2".
  • 22 is truthy, so or short-circuits and returns 22.
  • 22 is of type int.
Accepted Answers: int

Topic: Subscriptability (TypeError) | Marks: 2

Question 6

What will be the output type of the expression 555[2]?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Subscriptability: Indexing ([...]) is allowed on sequences (like strings, lists, tuples) but not on numeric types like int.

Procedure

  • 555555 is an int.
  • Integers are not "subscriptable".
  • Attempting to index an integer raises a TypeError.
Accepted Answers: Invalid Expression (raises an error)

Topic: String Indexing | Marks: 2

Question 7

What will be the output type of the expression "555"[2]?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Sequence Indexing: Strings are sequences. Indexing a string returns a string containing the character at that position.

Procedure

  • "555" is a string.
  • Index 22 exists (pointing to the third character).
  • Result is the string "5".
Accepted Answers: str

Topic: String Slicing | Marks: 2

Question 8

What will be the output type of the expression "555"[:2]?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Slicing: Slicing a string returns a new string containing the specified range.

Procedure

  • "555"[:2] returns the substring from start to index 11 (exclusive of 22).
  • Result is "55".
  • Type is str.
Accepted Answers: str

Question 9

What will be the output type of the expression 555[::2]?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  • Same as Question 6: int is not subscriptable.
Accepted Answers: Invalid Expression (raises an error)

Topic: Index Type Errors | Marks: 2

Question 10

What will be the output type of the expression "555"["2"]?
  • int
  • float
  • str
  • bool
  • Invalid Expression (raises an error)
Solution

Abstract Solution (Strategy)

  1. Index Type: String indices must be integers or slices, not strings.

Procedure

  • ["2"] uses a string literal as an index.
  • Python raises TypeError: string indices must be integers.
  • Note: The original prompt had an extra quote typo "555""['2']", but the core issue is the string index.
Accepted Answers: Invalid Expression (raises an error)

Topic: Explicit Type Casting | Marks: 2

Question 11

What will be the output type of the expression 5 + float(2)?
  • int
  • float
  • str
  • bool
  • Raises an error
Solution

Abstract Solution (Strategy)

  1. Explicit Type Casting: float(2) converts the integer 22 to 2.02.0.
  2. Arithmetic with Float: Any operation involving a float results in a float.

Procedure

  • 5 + 2.0 = 7.0.
  • Type is float.
Accepted Answers: float

Question 12

What will be the output type of the expression int(5.0) + float("2")?
  • int
  • float
  • str
  • bool
  • Raises an error
Solution

Abstract Solution (Strategy)

  • int(5.0) \to 5 (int)
  • float("2") \to 2.0 (float)
  • 5 + 2.0 = 7.0 (float)
Accepted Answers: float

Topic: String Concatenation | Marks: 2

Question 13

What will be the output type of the expression str(5) + str(2.0)?
  • int
  • float
  • str
  • bool
  • Raises an error
Solution

Abstract Solution (Strategy)

  1. String Concatenation: The + operator between two strings performs concatenation.

Procedure

  • "5" + "2.0" evaluates to "52.0".
  • Type is str.
Accepted Answers: str

Topic: Operator Precedence (MDAS) | Marks: 3

Question 14

Select the expression(s) that are equivalent to the given expression:
python
3 + 4 * 5 // 2
  • 3 + (4 * (5 // 2))
  • 3 + ((4 * 5) // 2)
  • (3 + 4) * (5 // 2)
  • ((3 + 4) * 5) // 2
Solution

Abstract Solution (Strategy)

  1. Operator Precedence: In Python, * and // have higher precedence than +.
  2. Associativity: * and // have the same precedence and associate from left to right. ^operator-precedence-rule

Procedure

  • Higher precedence first: 4 * 5 // 2.
  • Left-to-right: (4 * 5) // 2.
  • Finally addition: 3 + ((4 * 5) // 2).
Accepted Answers: 3 + ((4 * 5) // 2)

Topic: Exponentiation Precedence | Marks: 3

Question 15

Select the expression(s) that are equivalent to the given expression:
python
10 // 2 * 5 ** 2
  • ((10 // 2) * 5) ** 2
  • (10 // 2) * (5 ** 2)
  • 10 // ((2 * 5) ** 2)
  • (10 // (2 * 5)) ** 2
Solution

Abstract Solution (Strategy)

  1. Precedence Hierarchy:
    • ** (Exponentiation) - Highest
    • //, * (Multiplication/Division)
    • +, -
  2. Evaluation: Evaluate ** first, then evaluate // and * from left to right. ^math-precedence-hierarchy

Procedure

  • 5 ** 2 evaluates first.
  • 10 // 2 then the result multiplied by (52)(5^2).
  • Grouping: (10 // 2) * (5 ** 2).
Accepted Answers: (10 // 2) * (5 ** 2)

Question 16

Select the expression(s) that are equivalent to the given expression:
python
(1 + 2) * (3 + 4)
  • (1 + (2 * (3 + 4)))
  • (1 + 2) * 3 + 4
  • ((1 + 2) * (3 + 4))
  • 1 + (2 * 3) + 4
Solution

Abstract Solution (Strategy)

  • Parantheses already explicitly define the order. Outer parantheses are redundant but equivalent.
Accepted Answers: ((1 + 2) * (3 + 4))

Topic: Comparison vs Arithmetic Precedence | Marks: 3

Question 17

Select the expression(s) that are equivalent to the given expression:
python
4 + 3 > 2 * 1
  • (4 + 3) > (2 * 1)
  • 4 + (3 > (2 * 1))
  • (4 + 3 > 2) * 1
  • 4 + (3 > 2) * 1
Solution

Abstract Solution (Strategy)

  1. Precedence: Arithmetic (+, *) has higher precedence than Comparison (>).

Procedure

  • Evaluate 4 + 3 and 2 * 1 before comparing.
  • Equivalent to (4 + 3) > (2 * 1).
Accepted Answers: (4 + 3) > (2 * 1)

Topic: Logical Precedence (NOT AND OR) | Marks: 3

Question 18

Select the expression(s) that are equivalent to the given expression:
python
a and not b or not c
  • (a and (not b)) or (not c)
  • (a and not b) or (not c)
  • a and (not (b or not c))
  • a and ((not b) or (not c))
Solution

Abstract Solution (Strategy)

  1. Logical Precedence:
    • not (Highest)
    • and
    • or (Lowest) ^logical-precedence-rule

Procedure

  • not b and not c are evaluated first.
  • Then a and (not b).
  • Finally the or with (not c).
Accepted Answers: (a and (not b)) or (not c) (a and not b) or (not c)

Topic: Right-Associativity of Exponentiation | Marks: 3

Question 19

How does the Python interpreter parenthesize the following expression?
python
0 ** 1 ** 2 ** 3 ** 2
  • (((0 ** 1) ** 2) ** 3) ** 2
  • (0 ** (((1 ** 2) ** 3) ** 2))
  • 0 ** (1 ** (2 ** (3 ** 2)))
  • (0 ** ((1 ** 2) ** (3 ** 2)))
Solution

Abstract Solution (Strategy)

  1. Right-Associativity: The exponentiation operator ** is right-associative in Python, meaning it evaluates from right to left.

Procedure

  • xyzx ** y ** z is x(yz)x ** (y ** z).
  • Here: 0 ** (1 ** (2 ** (3 ** 2))).
Accepted Answers: 0 ** (1 ** (2 ** (3 ** 2)))

Topic: Print Function Properties | Marks: 2

Question 20

Select the correct statement(s) about print in Python.
  • print is a keyword.
  • print can be used to display any data type.
  • print at least requires one value.
  • print prints a newline character at the end of the line.
Solution

Abstract Solution (Strategy)

  1. Identify Function Type: print is a built-in function, not a keyword.
  2. Utility: It converts arguments to their string representations.
  3. Defaults: The default end parameter is \n.
  4. Empty Print: Calling print() outputs a single newline and is valid.
Accepted Answers: print can be used to display any data type. print prints a newline character at the end of the line.

Topic: Input Function Properties | Marks: 2

Question 21

Select the correct statement(s) about input in Python.
  • Output type can be passed to input as input(type) to get output in the required type.
  • input accepts at most one argument.
  • input is a built-in function.
  • input can only be used in Python scripts and not in REPL/Notebook.
Solution

Abstract Solution (Strategy)

  1. Signature: input(prompt=None) - only takes one optional string argument.
  2. Type: Always returns a str. One must explicitly wrap it (e.g., int(input())).
  3. Nature: It is a built-in function globally available.
Accepted Answers: input accepts at most one argument. input is a built-in function.

Question 22

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.
What is the value of a after executing line 3, using the input already given?
Solution
  • Line 1: a = 5
  • Line 2: a = 5 - 1 = 4
  • Line 3: a = 4 * 3 = 12
Accepted Answers: (Type: String) 12

Question 23

What is the value of a after executing line 4 (a += 4), if the input is changed to 14?
Solution
  • Line 1: a = 14
  • Line 2: a = 13
  • Line 3: a = 39
  • Line 4: a = 39 + 4 = 43
Accepted Answers: (Type: String) 43

Question 24

What is the value of a after executing line 5 (a //= 2), if the input is changed to 23?
Solution
  • Line 1: a = 23
  • Line 2: a = 22
  • Line 3: a = 66
  • Line 4: a = 70
  • Line 5: a = 70 // 2 = 35
Accepted Answers: (Type: String) 35

Question 25

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.
What is the value of a after executing line 3, using the input already given?
Solution
  • Line 1: a = 4
  • Line 2: a = 4 + 3 = 7
  • Line 3: a = 7 - 2 = 5
Accepted Answers: (Type: String) 5

Question 26

What is the value of a after executing line 4 (a *= 5), if the input is changed to 13?
Solution
  • Line 1: a = 13
  • Line 2: a = 16
  • Line 3: a = 14
  • Line 4: a = 14 * 5 = 70
Accepted Answers: (Type: String) 70

Question 27

What is the value of a after executing line 5 (a //= 2), if the input is changed to 8?
Solution
  • Line 1: a = 8
  • Line 2: a = 11
  • Line 3: a = 9
  • Line 4: a = 45
  • Line 5: a = 45 // 2 = 22
Accepted Answers: (Type: String) 22

Topic: String Slicing practice | Marks: 2

Question 28

Common data for the next 2 questions
python
word = '138412345678901938'
Find a and b such that word[a:b] == '123456789'.
Solution
  • Indices of '123456789' in the string:
    • 1: index 0
    • 3: index 1
    • 8: index 2
    • 4: index 3
    • 1: index 4
    • 2: index 5
    • ...
    • 9: index 12
  • The sequence '123456789' starts at index 4 and ends at index 12.
  • Slicing [a:b] is inclusive of a, exclusive of b.
  • So a = 4, b = 13.
Accepted Answers: (Type: String) 4

Question 29

Enter the value of b.
Accepted Answers: (Type: String) 13

Topic: Logical Negation Patterns | Marks: 4

Question 30

EE is a boolean variable. Pattern: not E, not not E, ... Line 500 evaluates to False. What is the value of EE?
Solution
  • Line 1: not E
  • Line 2: not not E (EE)
  • Line 3: not E
  • Line nn is EE if nn is even, and not E if nn is odd.
  • Line 500 is even     \implies it evaluates to EE.
  • Since Line 500 is False, E=FalseE = \text{False}.
Accepted Answers: False



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.