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

Worksheet 3

The document contains Python code snippets that define several functions for manipulating lists and strings. Functions include ChangeVal for modifying list values based on divisibility, change for altering the case of characters in a string, Change for calculating a sum based on list elements, and Changer for performing arithmetic operations. Each function is followed by example calls and print statements to demonstrate their outputs.

Uploaded by

sijajoseph
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)
5 views1 page

Worksheet 3

The document contains Python code snippets that define several functions for manipulating lists and strings. Functions include ChangeVal for modifying list values based on divisibility, change for altering the case of characters in a string, Change for calculating a sum based on list elements, and Changer for performing arithmetic operations. Each function is followed by example calls and print statements to demonstrate their outputs.

Uploaded by

sijajoseph
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

def ChangeVal(M,N): def ChangeVal(M,N):

for i in range(N): for i in range(N):


if M[i] % 5 == 0: if M[i] % 5 == 0:
M[i] //= 5 M[i] //= 5
if M[i] % 3 == 0: if M[i] % 3 == 0:
M[i] //= 3 M[i] //= 3
L = [25,8,75,12] L = [25,8,75,12]
ChangeVal(L,4) ChangeVal(L,4)
for i in L: for i in L:
print(i,end="#") print(i,end="#")

Name="PythoN3.1" Name="PythoN3.1"
R="" R=""
def change(Name,R): def change(Name,R):
for x in range(len(Name)): for x in range(len(Name)):
if Name[x].isupper(): if Name[x].isupper():
R = R + Name[x].lower() R = R + Name[x].lower()
elif Name[x].islower(): elif Name[x].islower():
R = R + Name[x].upper() R = R + Name[x].upper()
elif Name[x].isdigit(): elif Name[x].isdigit():
R = R + Name[x-1] R = R + Name[x-1]
else: else:
R = R + "#" R = R + "#"
print('R inside function',R) print('R inside function',R)
change(Name,R) change(Name,R)
print('R inside function',R) print('R inside function',R)

def Change(A): def Change(A):


S=0 S=0
for i in range(len(A)//2): for i in range(len(A)//2):
print(A[i]) print(A[i])
S += (A[i] * 2) S += (A[i] * 2)
return S return S
B = [10,11,12,30,32,34,35,38,40,2] B = [10,11,12,30,32,34,35,38,40,2]
C = Change(B) C = Change(B)
print('Output is', C) print('Output is', C)

def Changer(P,Q=10): def Changer(P,Q=10):


P=P/Q P=P/Q
Q=P%Q Q=P%Q
print(P,"#",Q) print(P,"#",Q)
return P return P
A=200;B=20 A=200;B=20
A=Changer(A,B) A=Changer(A,B)
print(A,"$",B) print(A,"$",B)
B=Changer(B) B=Changer(B)
print(A,"$",B) print(A,"$",B)
A=Changer(A) A=Changer(A)
print(A,"$",B) print(A,"$",B)

You might also like