Max Marks: 60
Time: 2 1/2 Hours
Instruction: Answer any 4 Questions from each Part
PART-A
I. Answer any Four questions. Each question carries 2 Marks. (4×2=8)
1. What is the purpose of indentation in Python?
Python indentation refers to adding white space before a statement to
a particular block of code. In another word, all the statements with the
same space to the right, belong to the same code block.
If proper indentation is not given then we will end up seeing
indentation errors and the code will not get compiled.
2. Define the "if..elif..else" decision control statement in Python.
The if else statement is used to execute a block of code among two
alternatives. However if we in to make a choice between more than
two alternatives, then we use the if elif else statement The if elif else
statement is a multi-way decision maker which contains two or more
branches from which any one block is executed.
Example:
marks = int (input("Enter the marks :"))
if marks> 85 and marks <=100:
, print("Congrats! You scored grade A")
elif marks>60 and marks<=85:
print("You scored grade B+")
elif marks> 40 and marks <=60
print("You scored grade B")
elif marks>30 and marks<=40
print("You scored grade C")
else print("Failed")
Output:
Enter the marks 89 Congrats!! You scored grade A
Enter the marks: 67
You scored grade B+
Enter the marks:14
Failed
3. What is the difference between a list and a tuple in Python?
SR.NO. LIST TUPLE
1 Lists are mutable Tuples are immutable
The implication of iterations is Time- The implication of iterations is
2 consuming comparatively Faster
, SR.NO. LIST TUPLE
The list is better for performing
operations, such as insertion and Tuple data type is appropriate
3 deletion. for accessing the elements
Tuple consumes less memory
4 Lists consume more memory as compared to the list
4. Explain the built-in functions used on dictionaries in Python
1) len(): The len() function returns the number of items (key:value
pairs) in a dictionary.
Syntax: len(dictionary_name)
>>> myDict = {1: 'A', 2: 'B', 3: 'C', 4: 'D'}
>>> len (myDict)
4
2) any(): The any() function returns Boolean True value if any of the key
in the dictionary is True else returns False.
Syntax: any(dictionary_name)
>>> myDict = {1: 'A', 2: 'B', 3: 'C', False: 'D'}
>>> any (myDict)
True
>>> myDict = {0: 'A', False: 'B'}
>>> any (myDict)