0% found this document useful (0 votes)
52 views1 page

Worksheet 3

This document contains 5 questions related to Python functions. Question 1 asks to write a function to separately sum the odd and even values in a list. Question 2 asks to find the output of a given function. Question 3 asks to write a function to count the occurrences of a letter in a string. Question 4 asks to write a function to perform a binary search on a list. Question 5 shows code for a function and asks to print the output when calling that function.

Uploaded by

Himanshu.tewari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views1 page

Worksheet 3

This document contains 5 questions related to Python functions. Question 1 asks to write a function to separately sum the odd and even values in a list. Question 2 asks to find the output of a given function. Question 3 asks to write a function to count the occurrences of a letter in a string. Question 4 asks to write a function to perform a binary search on a list. Question 5 shows code for a function and asks to print the output when calling that function.

Uploaded by

Himanshu.tewari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

WORKSHEET 2

Q1. Write definition of a method/function AddOddEven(VALUES) to display sum of odd and even values separately from the list
of VALUES.
For example : If the VALUES contain [15, 26, 37, 10, 22, 13] The function should display Even Sum: 58 Odd Sum: 65
Q2. Find and write the output of the following python code:
def fun(s):
k=len(s)
m=" "
for i in range(0,k):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else:
m=m+'bb'
print(m)
fun('school2@com')
Q3. Write a Python function to determine how many times a given letter occurs in a string.
Q4. Write a Python function to binary search a list
Q5. Show output of following:
def Show(STR, KEY):
x=0
L=len(STR)?
while X < (L//2):
if X%2 is not 1:
print( STR[X] * KEY )
else:
print( STR|X] * (KEY+1) )
x+=1
KEY+=2
show(”PYTHON”,1) #calling function show()

You might also like