Assignment No: 1 Subject: Computer Science Class: XII
Post Date: 21.3.2025 Submit Date: 25.3.2025
Question & Answer
1. What are Tokens in Python?
Ans: Tokens are the smallest units of a Python program. The Python interpreter breaks the code into tokens
for execution. Tokens in Python include:
1. Keywords: Reserved words like if, else, for, while, def, etc.
2. Identifiers: Names given to variables, functions, and classes.
3. Literals: Fixed values like numbers (10, 20.5), strings ("hello"), and booleans (True, False).
4. Operators: Symbols for operations, e.g., +, -, *, and, or.
5. Delimiters: Symbols like (), {}, ,, and : used to structure code.
2. What are Data Types in Python?
Ans: Data types define the kind of data stored in a variable. Python has several built-in data types:
Numeric Types: int (e.g., 10), float (e.g., 10.5), complex (e.g., 3+4j).
Sequence Types: list, tuple, range, str.
Mapping Type: dict (dictionary).
Set Types: set, frozenset.
Boolean Type: bool (True or False).
Binary Types: bytes, bytearray, memoryview.
3. What are Mutable and Immutable Data Types?
Ans:
Mutable Data Types: Can be changed after creation. Examples: list, dict, set, bytearray.
Immutable Data Types: Cannot be changed after creation. Examples: int, float, str, tuple.
4. What is an Expression in Python?
Ans: An expression is a combination of values, variables, and operators that produces a result. For example:
x = 5 + 3 # Expression: 5 + 3
Here, 5 + 3 is an expression that evaluates to 8.
5. What is a Statement and Flow Control in Python?
Ans: A statement is an instruction that the Python interpreter can execute. Examples include assignment (x =
10), print (print("Hello")), and loop statements (for, while).
Flow control refers to controlling the execution sequence of statements using:
1. Conditional Statements: if, elif, else.
2. Looping Statements: for, while.
3. Jump Statements: break, continue, pass.
6. What are Loop and Jump Statements in Python?
Ans:
Loop Statements: Used to execute a block of code multiple times.
o for loop: Iterates over sequences.
o while loop: Repeats as long as a condition is true.
Jump Statements: Used to alter loop execution.
o break: Exits the loop.
o continue: Skips the current iteration.
o pass: Does nothing, acts as a placeholder.
Multiple Choice Questions
1. Which of the following is an immutable data type in Python?
o a) List
o b) Dictionary
o c) Tuple
o d) Set
Answer: c) Tuple
2. What is used to terminate a loop in Python?
o a) break
o b) continue
o c) pass
o d) return
Answer: a) break
3. Which of the following is NOT a Python keyword?
o a) for
o b) while
o c) int
o d) def
Answer: c) int
Short Answers
1. What are the troubleshooting options for a syntax error in Python?
2. Differentiate between break and continue statements in Python.
3. Write a short note on if-else statements.
4. How many types of loops are there in Python? Explain briefly.
5. Explain Type Casting with example.
Case-Based Questions (CBQs)
Solved CBQ
Rahul wrote a program in Python that runs indefinitely and does not stop. What could be the possible issue?
Ans: He may have used a while loop without a proper termination condition.
Unsolved CBQs
1. Your friend wrote a Python program but got a Type Error. What could be the possible reasons?
2. A loop in your Python program is not executing at all. What could be the issue?