Worksheet 3
Worksheet 3
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()