Page 17 - IPP-11
P. 17
(f) Explain the following List methods with examples— (3)
Ans. (i) count ()
(ii) pop ()
(iii) extend ()
QUESTION 7
(a) What is argument? Give an example. (1)
Ans. List of variables/objects passed to functions or variables/objects that carry values from function call
statement to function definition.
Example:
def greet(name,msg):
"""This function greets to
the person with the provided message"""
print("Hello",name + ', ' + msg)
greet("Rinku","Good morning!")
(b) Rewrite the following code after removing errors, if any, and underline each correction— (1)
def func1()
input("input numbers:")
return number
Ans. def func1():
number = input("input numbers:")
return number
(c) Write any four Python’s built-in string manipulation methods with examples. (2)
Ans. string.capitalize(), string.isalnum(), string.isalpha(),
string.isdigit(), string.isspace(), string.islower(),
string.isupper(), string.lower(), string.upper() or any other
function with example
(d) Write a program that reads a string and then prints a string that capitalizes every other letter in the string,
e.g., passion becomes pAsSiOn. (3)
Ans. string=input("Enter a string:")
length=len(string)
print("Original String:",string)
string2=""
for a in range(0,length,2):
string2+=string[a]
if a<(length-1):
string2+=string[a+1].upper()
print("Alternatively capitalized string:", string2)
(e) Explain the following terms— (3)
Ans. (i) Module – Named block of statements within a program.
(ii) Function – Named independent grouping of code and data.
(iii) Namespace – Named logical environment holding logical grouping of related objects.
7