Neural Sync Active
Week 1 Graded Assignment 1
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)
- Identify Operands: Both operands are integers (5 and 2).
- Identify Operator: Addition (+) between two integers results in an integer in Python. ^python-w1-q1-strategy
Procedure
- 5 is of type
int. - 2 is of type
int. 5 + 2evaluates to 7, which is anint.
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)
- 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 / 2is2.0).
Procedure
- 5/2 evaluates to 2.5.
- 2.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)
- Mixed Type Promotion: If any operand in an arithmetic operation is a
float, the result is promoted to afloat. - Operator: Exponentiation (
**).
Procedure
- 5 is
int, 2.0 isfloat. - 52.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)
- 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)
- Short-circuiting: In Python,
x and yreturns x if x is falsy, otherwise it returns y.x or yreturns x if x is truthy, otherwise it returns y. - Truthiness: Non-zero integers are truthy.
- Precedence:
andhas higher precedence thanor. ^short-circuit-logic
Procedure
5 and 2: 5 is truthy, so it returns 2.- The expression becomes
2 or "2". - 2 is truthy, so
orshort-circuits and returns 2. - 2 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)
- Subscriptability: Indexing (
[...]) is allowed on sequences (like strings, lists, tuples) but not on numeric types likeint.
Procedure
- 555 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)
- Sequence Indexing: Strings are sequences. Indexing a string returns a string containing the character at that position.
Procedure
"555"is a string.- Index 2 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)
- Slicing: Slicing a string returns a new string containing the specified range.
Procedure
"555"[:2]returns the substring from start to index 1 (exclusive of 2).- 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:
intis 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)
- 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)
- Explicit Type Casting:
float(2)converts the integer 2 to 2.0. - 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)
- 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:
python3 + 4 * 5 // 2
-
3 + (4 * (5 // 2)) -
3 + ((4 * 5) // 2) -
(3 + 4) * (5 // 2) -
((3 + 4) * 5) // 2
Solution
Abstract Solution (Strategy)
- Operator Precedence: In Python,
*and//have higher precedence than+. - 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:
python10 // 2 * 5 ** 2
-
((10 // 2) * 5) ** 2 -
(10 // 2) * (5 ** 2) -
10 // ((2 * 5) ** 2) -
(10 // (2 * 5)) ** 2
Solution
Abstract Solution (Strategy)
- Precedence Hierarchy:
**(Exponentiation) - Highest//,*(Multiplication/Division)+,-
- Evaluation: Evaluate
**first, then evaluate//and*from left to right. ^math-precedence-hierarchy
Procedure
5 ** 2evaluates first.10 // 2then the result multiplied by (52).- 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:
python4 + 3 > 2 * 1
-
(4 + 3) > (2 * 1) -
4 + (3 > (2 * 1)) -
(4 + 3 > 2) * 1 -
4 + (3 > 2) * 1
Solution
Abstract Solution (Strategy)
- Precedence: Arithmetic (
+,*) has higher precedence than Comparison (>).
Procedure
- Evaluate
4 + 3and2 * 1before 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:
pythona 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)
- Logical Precedence:
not(Highest)andor(Lowest) ^logical-precedence-rule
Procedure
not bandnot care evaluated first.- Then
a and (not b). - Finally the
orwith(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?
python0 ** 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)
- Right-Associativity: The exponentiation operator
**is right-associative in Python, meaning it evaluates from right to left.
Procedure
- x∗∗y∗∗z is 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.-
printis a keyword. -
printcan be used to display any data type. -
printat least requires one value. -
printprints a newline character at the end of the line.
Solution
Abstract Solution (Strategy)
- Identify Function Type:
printis a built-in function, not a keyword. - Utility: It converts arguments to their string representations.
- Defaults: The default
endparameter is\n. - 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. -
inputaccepts at most one argument. -
inputis a built-in function. -
inputcan only be used in Python scripts and not in REPL/Notebook.
Solution
Abstract Solution (Strategy)
- Signature:
input(prompt=None)- only takes one optional string argument. - Type: Always returns a
str. One must explicitly wrap it (e.g.,int(input())). - 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
pythonword = '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 ofa, exclusive ofb. - 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
E is a boolean variable. Pattern:
not E, not not E, ...
Line 500 evaluates to False. What is the value of E?Solution
- Line 1:
not E - Line 2:
not not E(E) - Line 3:
not E - Line n is E if n is even, and
not Eif n is odd. - Line 500 is even ⟹ it evaluates to E.
- Since Line 500 is
False, E=False.
Accepted Answers:
False
🧭 Navigation
- 📘 Textbook Notes: Week 1 Notes
- 📝 Assignment: Week 1 Assignment 1
- 📝 Assignment: Week 1 Assignment 2
- ➡️ Next Week: Week 2 Notes