Functions - Worksheet
Functions - Worksheet
Functions - Worksheet
WORKSHEET – 2
1. Consider the code given below:
else:
if i.islower():
newstr=newstr+i.upper()
else:
newstr=newstr+i
count+=1
print(newstr)
makenew("No@l")
12. Predict the output:
def Update(X=10):
X += 15
print('X = ', X)
X=20
Update()
print('X = ', X)
13. Write a function dispBook(BOOKS) in Python, that takes a
dictionary BOOKS as an argument and displays the names in
uppercase of those books whose name starts with a consonant.
For example, Consider the following dictionary
BOOKS = {1:"Python", 2:"Internet Fundamentals ", 3:"Networking ",
4:"Oracle sets", 5:"Understanding HTML"}
The output should be:
PYTHON
NETWORKING
14. Write a Python Program containing a function FindWord(STRING,
SEARCH), that accepts two arguments : STRING and SEARCH, and
prints the count of occurrence of SEARCH in STRING. Write
appropriate statements to call the function.
For example, if STRING = "Learning history helps to know about
history with interest in history" and SEARCH = 'history', the
function should display ‘The word history occurs 3 times’.
15. Write a function EOReplace() in Python, which
accepts a list L of numbers. Thereafter, it increments
all even numbers by 1 and decrements all odd numbers
by 1.
Example:
If Sample Input data of the list is :
L=[10,20,30,40,35,55]
Output will be :
L=[11,21,31,41,34,54]
16. Write a function INDEX_LIST(L), where L is the list of elements
passed as argument to the function. The function returns another
list named ‘indexList’ that stores the indices of all Non-Zero
Elements of L.
For example:
If L contains [12,4,0,11,0,56]
The indexList will have - [0,1,3,5]