PWP Question Bank
PWP Question Bank
2 Marks Questions
Answer:
1. Interactive: Python provides an interactive shell for testing and debugging.
2. Object-Oriented: Supports object-oriented programming concepts like
inheritance and polymorphism.
3. Interpreted: No need to compile; the Python interpreter directly executes
the code.
4. Platform-Independent: Can run on different operating systems without
modifications.
Answer:
Indentation in Python defines the structure of the code. Instead of braces ({})
used in other languages, Python uses indentation to indicate blocks of code.
Example:
if True:
print("Indented block is part of 'if'")
print("This is outside the 'if' block")
Answer:
Keywords are reserved words in Python that have predefined meanings and
cannot be used as variable names.
Examples: if, else, return, for, while.
Example usage:
if True:
print("This is a keyword example")
Q4: List identity operators in Python.
Answer:
Identity operators in Python are:
my_tuple = (1, 2, 3)
4 Marks Questions
Answer:
Q2: List the data types in Python and explain any two with examples.
Answer:
a) Arithmetic Operators
# Taking two numbers as input
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
b) Logical Operators
# Taking two boolean values as input
x = bool(int(input("Enter 1 for True or 0 for False (x): ")))
y = bool(int(input("Enter 1 for True or 0 for False (y): ")))
c) Bitwise Operators
# Taking two numbers as input
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
a) 'while' loop
b) 'for' loop
c) Nested loops
Answer:
a) while loop:
b) for loop:
c) Nested loops:
Answer:
Control flow statements alter the flow of a program:
# a) Create Tuple
my_tuple = (1, 2, 3, 4, 5)
print("Created Tuple:", my_tuple)
# b) Access Tuple
print("First element:", my_tuple[0])
print("Last element:", my_tuple[-1])
# c) Update Tuple
# Since tuples are immutable, we can't modify them directly.
# But we can create a new tuple by combining or slicing.
new_tuple = my_tuple + (6,) # Adding 6 to the tuple
print("New tuple after adding 6:", new_tuple)
# d) Delete Tuple
del my_tuple
Output -
Created Tuple: (1, 2, 3, 4, 5)
First element: 1
Last element: 5
New tuple after adding 6: (1, 2, 3, 4, 5, 6)
The tuple has been deleted.